@coinbase/agentkit 0.1.1 → 0.2.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 +338 -5
- 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/basename/basenameActionProvider.d.ts +1 -1
- package/dist/action-providers/cdp/cdpApiActionProvider.js +7 -1
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +1 -1
- package/dist/action-providers/erc20/schemas.d.ts +2 -2
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +1 -1
- package/dist/action-providers/index.d.ts +8 -5
- package/dist/action-providers/index.js +8 -5
- 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/morphoActionProvider.d.ts +1 -1
- package/dist/action-providers/morpho/schemas.d.ts +4 -4
- 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/spl/index.d.ts +1 -0
- package/dist/action-providers/spl/index.js +17 -0
- package/dist/action-providers/spl/schemas.d.ts +17 -0
- package/dist/action-providers/spl/schemas.js +14 -0
- package/dist/action-providers/spl/splActionProvider.d.ts +37 -0
- package/dist/action-providers/spl/splActionProvider.js +112 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +206 -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/action-providers/weth/wethActionProvider.d.ts +1 -1
- package/dist/action-providers/wow/wowActionProvider.d.ts +1 -1
- 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 +14 -0
- package/dist/network/svm.js +33 -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 +31 -8
- package/dist/wallet-providers/index.d.ts +3 -0
- package/dist/wallet-providers/index.js +3 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +70 -0
- package/dist/wallet-providers/privyWalletProvider.js +139 -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 +23 -4
- 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", () => {
|
|
@@ -6,7 +6,7 @@ import { EvmWalletProvider } from "../../wallet-providers";
|
|
|
6
6
|
/**
|
|
7
7
|
* WethActionProvider is an action provider for WETH.
|
|
8
8
|
*/
|
|
9
|
-
export declare class WethActionProvider extends ActionProvider {
|
|
9
|
+
export declare class WethActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
10
|
/**
|
|
11
11
|
* Constructor for the WethActionProvider.
|
|
12
12
|
*/
|
|
@@ -6,7 +6,7 @@ import { WowBuyTokenInput, WowCreateTokenInput, WowSellTokenInput } from "./sche
|
|
|
6
6
|
/**
|
|
7
7
|
* WowActionProvider is an action provider for Wow protocol interactions.
|
|
8
8
|
*/
|
|
9
|
-
export declare class WowActionProvider extends ActionProvider {
|
|
9
|
+
export declare class WowActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
10
|
/**
|
|
11
11
|
* Constructor for the WowActionProvider class.
|
|
12
12
|
*/
|
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,14 @@
|
|
|
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>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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
|
+
};
|
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,14 +10,16 @@ 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
|
+
const package_json_1 = require("../../package.json");
|
|
16
17
|
const decimal_js_1 = require("decimal.js");
|
|
17
18
|
const viem_1 = require("viem");
|
|
18
19
|
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
19
20
|
const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
|
|
20
21
|
const network_1 = require("../network/network");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
21
23
|
/**
|
|
22
24
|
* A wallet provider that uses the Coinbase SDK.
|
|
23
25
|
*/
|
|
@@ -33,6 +35,8 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
33
35
|
_CdpWalletProvider_address.set(this, void 0);
|
|
34
36
|
_CdpWalletProvider_network.set(this, void 0);
|
|
35
37
|
_CdpWalletProvider_publicClient.set(this, void 0);
|
|
38
|
+
_CdpWalletProvider_gasLimitMultiplier.set(this, void 0);
|
|
39
|
+
_CdpWalletProvider_feePerGasMultiplier.set(this, void 0);
|
|
36
40
|
__classPrivateFieldSet(this, _CdpWalletProvider_cdpWallet, config.wallet, "f");
|
|
37
41
|
__classPrivateFieldSet(this, _CdpWalletProvider_address, config.address, "f");
|
|
38
42
|
__classPrivateFieldSet(this, _CdpWalletProvider_network, config.network, "f");
|
|
@@ -40,6 +44,8 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
40
44
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
41
45
|
transport: (0, viem_1.http)(),
|
|
42
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");
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* Configures a new CdpWalletProvider with a wallet.
|
|
@@ -50,7 +56,12 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
50
56
|
*/
|
|
51
57
|
static async configureWithWallet(config = {}) {
|
|
52
58
|
if (config.apiKeyName && config.apiKeyPrivateKey) {
|
|
53
|
-
coinbase_sdk_1.Coinbase.configure({
|
|
59
|
+
coinbase_sdk_1.Coinbase.configure({
|
|
60
|
+
apiKeyName: config.apiKeyName,
|
|
61
|
+
privateKey: config.apiKeyPrivateKey,
|
|
62
|
+
source: "agentkit",
|
|
63
|
+
sourceVersion: package_json_1.version,
|
|
64
|
+
});
|
|
54
65
|
}
|
|
55
66
|
else {
|
|
56
67
|
coinbase_sdk_1.Coinbase.configureFromJson();
|
|
@@ -86,6 +97,7 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
86
97
|
wallet,
|
|
87
98
|
address,
|
|
88
99
|
network,
|
|
100
|
+
gas: config.gas,
|
|
89
101
|
});
|
|
90
102
|
return cdpWalletProvider;
|
|
91
103
|
}
|
|
@@ -101,6 +113,9 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
101
113
|
}
|
|
102
114
|
const messageHash = (0, coinbase_sdk_1.hashMessage)(message);
|
|
103
115
|
const payload = await __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f").createPayloadSignature(messageHash);
|
|
116
|
+
if (payload.getStatus() === "pending" && payload?.wait) {
|
|
117
|
+
await payload.wait(); // needed for Server-Signers
|
|
118
|
+
}
|
|
104
119
|
return payload.getSignature();
|
|
105
120
|
}
|
|
106
121
|
/**
|
|
@@ -116,6 +131,9 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
116
131
|
}
|
|
117
132
|
const messageHash = (0, coinbase_sdk_1.hashTypedDataMessage)(typedData.domain, typedData.types, typedData.message);
|
|
118
133
|
const payload = await __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f").createPayloadSignature(messageHash);
|
|
134
|
+
if (payload.getStatus() === "pending" && payload?.wait) {
|
|
135
|
+
await payload.wait(); // needed for Server-Signers
|
|
136
|
+
}
|
|
119
137
|
return payload.getSignature();
|
|
120
138
|
}
|
|
121
139
|
/**
|
|
@@ -131,6 +149,9 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
131
149
|
const serializedTx = (0, viem_1.serializeTransaction)(transaction);
|
|
132
150
|
const transactionHash = (0, viem_1.keccak256)(serializedTx);
|
|
133
151
|
const payload = await __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f").createPayloadSignature(transactionHash);
|
|
152
|
+
if (payload.getStatus() === "pending" && payload?.wait) {
|
|
153
|
+
await payload.wait(); // needed for Server-Signers
|
|
154
|
+
}
|
|
134
155
|
return payload.getSignature();
|
|
135
156
|
}
|
|
136
157
|
/**
|
|
@@ -168,21 +189,23 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
168
189
|
address: __classPrivateFieldGet(this, _CdpWalletProvider_address, "f"),
|
|
169
190
|
});
|
|
170
191
|
const feeData = await __classPrivateFieldGet(this, _CdpWalletProvider_publicClient, "f").estimateFeesPerGas();
|
|
171
|
-
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({
|
|
195
|
+
account: __classPrivateFieldGet(this, _CdpWalletProvider_address, "f"),
|
|
172
196
|
to,
|
|
173
197
|
value,
|
|
174
198
|
data,
|
|
175
|
-
maxFeePerGas: feeData.maxFeePerGas,
|
|
176
|
-
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
|
|
177
199
|
});
|
|
200
|
+
const gas = BigInt(Math.round(Number(gasLimit) * __classPrivateFieldGet(this, _CdpWalletProvider_gasLimitMultiplier, "f")));
|
|
178
201
|
const chainId = parseInt(__classPrivateFieldGet(this, _CdpWalletProvider_network, "f").chainId, 10);
|
|
179
202
|
return {
|
|
180
203
|
to,
|
|
181
204
|
value,
|
|
182
205
|
data,
|
|
183
206
|
nonce,
|
|
184
|
-
maxFeePerGas
|
|
185
|
-
maxPriorityFeePerGas
|
|
207
|
+
maxFeePerGas,
|
|
208
|
+
maxPriorityFeePerGas,
|
|
186
209
|
gas,
|
|
187
210
|
chainId,
|
|
188
211
|
type: "eip1559",
|
|
@@ -359,4 +382,4 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
359
382
|
}
|
|
360
383
|
}
|
|
361
384
|
exports.CdpWalletProvider = CdpWalletProvider;
|
|
362
|
-
_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,6 @@ 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";
|
|
@@ -18,3 +18,6 @@ __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);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ViemWalletProvider } from "./viemWalletProvider";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the Privy wallet provider.
|
|
4
|
+
*
|
|
5
|
+
* @interface
|
|
6
|
+
*/
|
|
7
|
+
interface PrivyWalletConfig {
|
|
8
|
+
/** The Privy application ID */
|
|
9
|
+
appId: string;
|
|
10
|
+
/** The Privy application secret */
|
|
11
|
+
appSecret: string;
|
|
12
|
+
/** The ID of the wallet to use, if not provided a new wallet will be created */
|
|
13
|
+
walletId?: string;
|
|
14
|
+
/** Optional chain ID to connect to */
|
|
15
|
+
chainId?: string;
|
|
16
|
+
/** Optional authorization key for the wallet API */
|
|
17
|
+
authorizationPrivateKey?: string;
|
|
18
|
+
/** Optional authorization key ID for creating new wallets */
|
|
19
|
+
authorizationKeyId?: string;
|
|
20
|
+
}
|
|
21
|
+
type PrivyWalletExport = {
|
|
22
|
+
walletId: string;
|
|
23
|
+
authorizationPrivateKey: string | undefined;
|
|
24
|
+
chainId: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
28
|
+
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
29
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PrivyWalletProvider extends ViemWalletProvider {
|
|
32
|
+
#private;
|
|
33
|
+
/**
|
|
34
|
+
* Private constructor to enforce use of factory method.
|
|
35
|
+
*
|
|
36
|
+
* @param walletClient - The Viem wallet client instance
|
|
37
|
+
* @param config - The configuration options for the Privy wallet
|
|
38
|
+
*/
|
|
39
|
+
private constructor();
|
|
40
|
+
/**
|
|
41
|
+
* Creates and configures a new PrivyWalletProvider instance.
|
|
42
|
+
*
|
|
43
|
+
* @param config - The configuration options for the Privy wallet
|
|
44
|
+
* @returns A configured PrivyWalletProvider instance
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const provider = await PrivyWalletProvider.configureWithWallet({
|
|
49
|
+
* appId: "your-app-id",
|
|
50
|
+
* appSecret: "your-app-secret",
|
|
51
|
+
* walletId: "wallet-id",
|
|
52
|
+
* chainId: "84532"
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
static configureWithWallet(config: PrivyWalletConfig): Promise<PrivyWalletProvider>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the name of the wallet provider.
|
|
59
|
+
*
|
|
60
|
+
* @returns The string identifier for this wallet provider
|
|
61
|
+
*/
|
|
62
|
+
getName(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Exports the wallet data.
|
|
65
|
+
*
|
|
66
|
+
* @returns The wallet data
|
|
67
|
+
*/
|
|
68
|
+
exportWallet(): PrivyWalletExport;
|
|
69
|
+
}
|
|
70
|
+
export {};
|