@coinbase/agentkit 0.0.0-nightly-20250918210440 → 0.0.0-nightly-20251001210424
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 +170 -39
- package/dist/action-providers/across/schemas.d.ts +1 -1
- package/dist/action-providers/baseAccount/baseAccountActionProvider.d.ts +46 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +404 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.d.ts +1 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.js +325 -0
- package/dist/action-providers/baseAccount/index.d.ts +2 -0
- package/dist/action-providers/baseAccount/index.js +18 -0
- package/dist/action-providers/baseAccount/schemas.d.ts +43 -0
- package/dist/action-providers/baseAccount/schemas.js +62 -0
- package/dist/action-providers/baseAccount/types.d.ts +17 -0
- package/dist/action-providers/baseAccount/types.js +2 -0
- package/dist/action-providers/baseAccount/utils.d.ts +14 -0
- package/dist/action-providers/baseAccount/utils.js +57 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.js +7 -30
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +2 -8
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +2 -1
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +3 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +2 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +3 -1
- package/dist/action-providers/cdp/faucetUtils.d.ts +38 -0
- package/dist/action-providers/cdp/faucetUtils.js +81 -0
- package/dist/action-providers/cdp/swapUtils.d.ts +0 -9
- package/dist/action-providers/cdp/swapUtils.js +0 -36
- package/dist/action-providers/clanker/schemas.d.ts +6 -6
- package/dist/action-providers/enso/constants.d.ts +4 -0
- package/dist/action-providers/enso/constants.js +10 -0
- package/dist/action-providers/enso/ensoActionProvider.d.ts +34 -0
- package/dist/action-providers/enso/ensoActionProvider.js +125 -0
- package/dist/action-providers/enso/ensoActionProvider.test.d.ts +1 -0
- package/dist/action-providers/enso/ensoActionProvider.test.js +141 -0
- package/dist/action-providers/enso/index.d.ts +1 -0
- package/dist/action-providers/enso/index.js +17 -0
- package/dist/action-providers/enso/schemas.d.ts +23 -0
- package/dist/action-providers/enso/schemas.js +22 -0
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +17 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +102 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +201 -0
- package/dist/action-providers/erc20/schemas.d.ts +29 -0
- package/dist/action-providers/erc20/schemas.js +34 -1
- package/dist/action-providers/flaunch/client_utils.d.ts +25 -0
- package/dist/action-providers/flaunch/client_utils.js +62 -0
- package/dist/action-providers/flaunch/constants.d.ts +41 -20
- package/dist/action-providers/flaunch/constants.js +111 -36
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +4 -43
- package/dist/action-providers/flaunch/flaunchActionProvider.js +132 -200
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +108 -13
- package/dist/action-providers/flaunch/metadata_utils.d.ts +12 -0
- package/dist/action-providers/flaunch/metadata_utils.js +216 -0
- package/dist/action-providers/flaunch/schemas.d.ts +39 -3
- package/dist/action-providers/flaunch/schemas.js +62 -10
- package/dist/action-providers/flaunch/{utils.d.ts → swap_utils.d.ts} +17 -19
- package/dist/action-providers/flaunch/{utils.js → swap_utils.js} +137 -172
- package/dist/action-providers/index.d.ts +4 -1
- package/dist/action-providers/index.js +4 -1
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +5 -4
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +2 -1
- package/dist/action-providers/superfluid/utils/parseLogs.js +6 -3
- package/dist/action-providers/wallet/walletActionProvider.js +3 -0
- package/dist/action-providers/x402/utils.d.ts +4 -4
- package/dist/action-providers/x402/utils.js +42 -5
- package/dist/action-providers/x402/x402ActionProvider.d.ts +6 -6
- package/dist/action-providers/x402/x402ActionProvider.js +23 -8
- package/dist/action-providers/x402/x402ActionProvider.test.js +50 -6
- package/dist/action-providers/yelay/constants.d.ts +64 -0
- package/dist/action-providers/yelay/constants.js +137 -0
- package/dist/action-providers/yelay/index.d.ts +2 -0
- package/dist/action-providers/yelay/index.js +18 -0
- package/dist/action-providers/yelay/schemas.d.ts +47 -0
- package/dist/action-providers/yelay/schemas.js +59 -0
- package/dist/action-providers/yelay/types.d.ts +24 -0
- package/dist/action-providers/yelay/types.js +2 -0
- package/dist/action-providers/yelay/yelayActionProvider.d.ts +70 -0
- package/dist/action-providers/yelay/yelayActionProvider.js +329 -0
- package/dist/action-providers/yelay/yelayActionProvider.test.d.ts +1 -0
- package/dist/action-providers/yelay/yelayActionProvider.test.js +302 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +43 -13
- package/dist/wallet-providers/cdpEvmWalletProvider.js +5 -21
- package/dist/wallet-providers/cdpSmartWalletProvider.js +10 -5
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +0 -8
- package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +14 -0
- package/dist/wallet-providers/cdpSolanaWalletProvider.js +39 -3
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +16 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +14 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +17 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +10 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +14 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +17 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +34 -0
- package/dist/wallet-providers/svmWalletProvider.js +43 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +10 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/viemWalletProvider.js +5 -1
- package/dist/wallet-providers/viemWalletProvider.test.js +12 -1
- package/package.json +4 -1
package/dist/utils.js
CHANGED
|
@@ -2,19 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.approve = approve;
|
|
4
4
|
exports.applyGasMultiplier = applyGasMultiplier;
|
|
5
|
+
exports.retryWithExponentialBackoff = retryWithExponentialBackoff;
|
|
5
6
|
const viem_1 = require("viem");
|
|
6
|
-
const
|
|
7
|
-
{
|
|
8
|
-
inputs: [
|
|
9
|
-
{ name: "spender", type: "address" },
|
|
10
|
-
{ name: "amount", type: "uint256" },
|
|
11
|
-
],
|
|
12
|
-
name: "approve",
|
|
13
|
-
outputs: [{ name: "", type: "bool" }],
|
|
14
|
-
stateMutability: "nonpayable",
|
|
15
|
-
type: "function",
|
|
16
|
-
},
|
|
17
|
-
];
|
|
7
|
+
const viem_2 = require("viem");
|
|
18
8
|
/**
|
|
19
9
|
* Approves a spender to spend tokens on behalf of the owner
|
|
20
10
|
*
|
|
@@ -27,7 +17,7 @@ const ERC20_ABI = [
|
|
|
27
17
|
async function approve(wallet, tokenAddress, spenderAddress, amount) {
|
|
28
18
|
try {
|
|
29
19
|
const data = (0, viem_1.encodeFunctionData)({
|
|
30
|
-
abi:
|
|
20
|
+
abi: viem_2.erc20Abi,
|
|
31
21
|
functionName: "approve",
|
|
32
22
|
args: [spenderAddress, amount],
|
|
33
23
|
});
|
|
@@ -55,3 +45,43 @@ async function approve(wallet, tokenAddress, spenderAddress, amount) {
|
|
|
55
45
|
function applyGasMultiplier(gas, multiplier) {
|
|
56
46
|
return BigInt(Math.round(Number(gas) * multiplier));
|
|
57
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Utility function to sleep for a given number of milliseconds
|
|
50
|
+
*
|
|
51
|
+
* @param ms - Number of milliseconds to sleep
|
|
52
|
+
* @returns Promise that resolves after the specified delay
|
|
53
|
+
*/
|
|
54
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
55
|
+
/**
|
|
56
|
+
* Retry function with exponential backoff
|
|
57
|
+
*
|
|
58
|
+
* @param fn - The function to retry
|
|
59
|
+
* @param maxRetries - Maximum number of retries (default: 3)
|
|
60
|
+
* @param baseDelay - Base delay in milliseconds for retries (default: 1000)
|
|
61
|
+
* @param initialDelay - Initial delay before the first attempt in milliseconds (default: 0)
|
|
62
|
+
* @returns Promise that resolves with the function result or rejects with the last error
|
|
63
|
+
*/
|
|
64
|
+
async function retryWithExponentialBackoff(fn, maxRetries = 3, baseDelay = 1000, initialDelay = 0) {
|
|
65
|
+
let lastError;
|
|
66
|
+
// Wait before the first attempt if initialDelay is specified
|
|
67
|
+
if (initialDelay > 0) {
|
|
68
|
+
await sleep(initialDelay);
|
|
69
|
+
}
|
|
70
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
71
|
+
try {
|
|
72
|
+
return await fn();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
lastError = error;
|
|
76
|
+
// If this was the last attempt, throw the error
|
|
77
|
+
if (attempt === maxRetries) {
|
|
78
|
+
throw lastError;
|
|
79
|
+
}
|
|
80
|
+
// Wait after failed attempt with exponential backoff
|
|
81
|
+
// Calculate delay with exponential backoff: baseDelay * 2^attempt
|
|
82
|
+
const delay = baseDelay * Math.pow(2, attempt);
|
|
83
|
+
await sleep(delay);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw lastError;
|
|
87
|
+
}
|
|
@@ -138,29 +138,13 @@ class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
138
138
|
* @returns The hash of the transaction.
|
|
139
139
|
*/
|
|
140
140
|
async sendTransaction(transaction) {
|
|
141
|
-
const txWithGasParams = {
|
|
142
|
-
...transaction,
|
|
143
|
-
chainId: __classPrivateFieldGet(this, _CdpEvmWalletProvider_network, "f").chainId,
|
|
144
|
-
};
|
|
145
|
-
if (!txWithGasParams.maxFeePerGas && !txWithGasParams.gasPrice) {
|
|
146
|
-
const feeData = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").estimateFeesPerGas();
|
|
147
|
-
txWithGasParams.maxFeePerGas = feeData.maxFeePerGas;
|
|
148
|
-
txWithGasParams.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
149
|
-
}
|
|
150
|
-
if (!txWithGasParams.gas) {
|
|
151
|
-
try {
|
|
152
|
-
txWithGasParams.gas = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").estimateGas({
|
|
153
|
-
account: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
154
|
-
...txWithGasParams,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
console.warn("Failed to estimate gas, continuing without gas estimation", error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
141
|
const result = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_cdp, "f").evm.sendTransaction({
|
|
162
142
|
address: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
163
|
-
transaction:
|
|
143
|
+
transaction: {
|
|
144
|
+
to: transaction.to,
|
|
145
|
+
value: transaction.value ? BigInt(transaction.value.toString()) : 0n,
|
|
146
|
+
data: transaction.data || "0x",
|
|
147
|
+
},
|
|
164
148
|
network: this.getCdpSdkNetwork(),
|
|
165
149
|
});
|
|
166
150
|
return result.transactionHash;
|
|
@@ -56,10 +56,6 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
56
56
|
throw new Error("Missing required environment variables. CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET are required.");
|
|
57
57
|
}
|
|
58
58
|
const networkId = config.networkId || process.env.NETWORK_ID || "base-sepolia";
|
|
59
|
-
// Smart wallets are currently only supported on Base networks
|
|
60
|
-
if (!networkId.startsWith("base-")) {
|
|
61
|
-
throw new Error(`Smart wallets are only supported on Base networks. Got: ${networkId}`);
|
|
62
|
-
}
|
|
63
59
|
const network = {
|
|
64
60
|
protocolFamily: "evm",
|
|
65
61
|
chainId: network_1.NETWORK_ID_TO_CHAIN_ID[networkId],
|
|
@@ -252,10 +248,19 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
252
248
|
// For smart wallets, we need to wait for the user operation to be confirmed
|
|
253
249
|
// This is a simplified implementation - in practice you might want to poll
|
|
254
250
|
// the CDP API for user operation status
|
|
255
|
-
|
|
251
|
+
const receipt = await __classPrivateFieldGet(this, _CdpSmartWalletProvider_cdp, "f").evm.waitForUserOperation({
|
|
256
252
|
smartAccountAddress: this.smartAccount.address,
|
|
257
253
|
userOpHash,
|
|
258
254
|
});
|
|
255
|
+
// Append transaction logs if available
|
|
256
|
+
if (receipt.status === "complete") {
|
|
257
|
+
const receiptTx = await __classPrivateFieldGet(this, _CdpSmartWalletProvider_publicClient, "f").getTransactionReceipt({
|
|
258
|
+
hash: receipt.transactionHash,
|
|
259
|
+
});
|
|
260
|
+
if (receiptTx.logs)
|
|
261
|
+
return { ...receipt, logs: receiptTx.logs };
|
|
262
|
+
}
|
|
263
|
+
return receipt;
|
|
259
264
|
}
|
|
260
265
|
/**
|
|
261
266
|
* Reads a contract.
|
|
@@ -142,14 +142,6 @@ describe("CdpSmartWalletProvider", () => {
|
|
|
142
142
|
expect(provider.getAddress()).toBe(MOCK_SMART_ADDRESS);
|
|
143
143
|
expect(provider.getNetwork()).toEqual(MOCK_NETWORK);
|
|
144
144
|
});
|
|
145
|
-
it("should throw error for non-Base networks", async () => {
|
|
146
|
-
await expect(cdpSmartWalletProvider_1.CdpSmartWalletProvider.configureWithWallet({
|
|
147
|
-
apiKeyId: "test-key-id",
|
|
148
|
-
apiKeySecret: "test-key-secret",
|
|
149
|
-
walletSecret: "test-wallet-secret",
|
|
150
|
-
networkId: "ethereum-sepolia",
|
|
151
|
-
})).rejects.toThrow("Smart wallets are only supported on Base networks");
|
|
152
|
-
});
|
|
153
145
|
it("should create smart account with name", async () => {
|
|
154
146
|
await cdpSmartWalletProvider_1.CdpSmartWalletProvider.configureWithWallet({
|
|
155
147
|
apiKeyId: "test-key-id",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
2
|
+
import type { KeyPairSigner } from "@solana/kit";
|
|
2
3
|
import { Connection, PublicKey, RpcResponseAndContext, SignatureResult, SignatureStatus, SignatureStatusConfig, VersionedTransaction } from "@solana/web3.js";
|
|
3
4
|
import { Network } from "../network";
|
|
4
5
|
import { WalletProviderWithClient, CdpWalletProviderConfig } from "./cdpShared";
|
|
@@ -109,6 +110,13 @@ export declare class CdpSolanaWalletProvider extends SvmWalletProvider implement
|
|
|
109
110
|
* @returns The CDP client.
|
|
110
111
|
*/
|
|
111
112
|
getClient(): CdpClient;
|
|
113
|
+
/**
|
|
114
|
+
* Sign a message.
|
|
115
|
+
*
|
|
116
|
+
* @param message - The message to sign as a Uint8Array
|
|
117
|
+
* @returns The signature as a Uint8Array
|
|
118
|
+
*/
|
|
119
|
+
signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
112
120
|
/**
|
|
113
121
|
* Transfer SOL from the wallet to another address
|
|
114
122
|
*
|
|
@@ -117,4 +125,10 @@ export declare class CdpSolanaWalletProvider extends SvmWalletProvider implement
|
|
|
117
125
|
* @returns The signature
|
|
118
126
|
*/
|
|
119
127
|
nativeTransfer(to: string, value: string): Promise<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Get the keypair signer for this wallet.
|
|
130
|
+
*
|
|
131
|
+
* @returns The KeyPairSigner
|
|
132
|
+
*/
|
|
133
|
+
getKeyPairSigner(): Promise<KeyPairSigner>;
|
|
120
134
|
}
|
|
@@ -10,11 +10,15 @@ 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
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _CdpSolanaWalletProvider_connection, _CdpSolanaWalletProvider_cdp, _CdpSolanaWalletProvider_network, _CdpSolanaWalletProvider_serverAccount;
|
|
14
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
18
|
exports.CdpSolanaWalletProvider = void 0;
|
|
16
19
|
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
17
20
|
const web3_js_1 = require("@solana/web3.js");
|
|
21
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
18
22
|
const svm_1 = require("../network/svm");
|
|
19
23
|
const svmWalletProvider_1 = require("./svmWalletProvider");
|
|
20
24
|
/**
|
|
@@ -29,9 +33,9 @@ class CdpSolanaWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
29
33
|
constructor(config) {
|
|
30
34
|
super();
|
|
31
35
|
_CdpSolanaWalletProvider_connection.set(this, void 0);
|
|
32
|
-
_CdpSolanaWalletProvider_serverAccount.set(this, void 0);
|
|
33
36
|
_CdpSolanaWalletProvider_cdp.set(this, void 0);
|
|
34
37
|
_CdpSolanaWalletProvider_network.set(this, void 0);
|
|
38
|
+
_CdpSolanaWalletProvider_serverAccount.set(this, void 0);
|
|
35
39
|
__classPrivateFieldSet(this, _CdpSolanaWalletProvider_serverAccount, config.serverAccount, "f");
|
|
36
40
|
__classPrivateFieldSet(this, _CdpSolanaWalletProvider_cdp, config.cdp, "f");
|
|
37
41
|
__classPrivateFieldSet(this, _CdpSolanaWalletProvider_connection, config.connection, "f");
|
|
@@ -216,6 +220,23 @@ class CdpSolanaWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
216
220
|
getClient() {
|
|
217
221
|
return __classPrivateFieldGet(this, _CdpSolanaWalletProvider_cdp, "f");
|
|
218
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Sign a message.
|
|
225
|
+
*
|
|
226
|
+
* @param message - The message to sign as a Uint8Array
|
|
227
|
+
* @returns The signature as a Uint8Array
|
|
228
|
+
*/
|
|
229
|
+
async signMessage(message) {
|
|
230
|
+
// Convert Uint8Array to string for CDP SDK
|
|
231
|
+
const messageString = Buffer.from(message).toString("utf8");
|
|
232
|
+
const { signature } = await __classPrivateFieldGet(this, _CdpSolanaWalletProvider_cdp, "f").solana.signMessage({
|
|
233
|
+
address: __classPrivateFieldGet(this, _CdpSolanaWalletProvider_serverAccount, "f").address,
|
|
234
|
+
message: messageString,
|
|
235
|
+
});
|
|
236
|
+
// Convert signature string back to Uint8Array
|
|
237
|
+
// CDP returns signature as a hex string, convert to bytes
|
|
238
|
+
return new Uint8Array(Buffer.from(signature, "hex"));
|
|
239
|
+
}
|
|
219
240
|
/**
|
|
220
241
|
* Transfer SOL from the wallet to another address
|
|
221
242
|
*
|
|
@@ -253,6 +274,21 @@ class CdpSolanaWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
253
274
|
await this.waitForSignatureResult(signature);
|
|
254
275
|
return signature;
|
|
255
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Get the keypair signer for this wallet.
|
|
279
|
+
*
|
|
280
|
+
* @returns The KeyPairSigner
|
|
281
|
+
*/
|
|
282
|
+
async getKeyPairSigner() {
|
|
283
|
+
// Export the private key from CDP
|
|
284
|
+
const exportedPrivateKey = await __classPrivateFieldGet(this, _CdpSolanaWalletProvider_cdp, "f").solana.exportAccount({
|
|
285
|
+
address: __classPrivateFieldGet(this, _CdpSolanaWalletProvider_serverAccount, "f").address,
|
|
286
|
+
});
|
|
287
|
+
// Decode the base58 encoded private key to get the full 64-byte key
|
|
288
|
+
const fullKeyBytes = bs58_1.default.decode(exportedPrivateKey);
|
|
289
|
+
// Create and return the KeyPairSigner using the full key bytes
|
|
290
|
+
return (0, svmWalletProvider_1.createSignerFromBytes)(fullKeyBytes);
|
|
291
|
+
}
|
|
256
292
|
}
|
|
257
293
|
exports.CdpSolanaWalletProvider = CdpSolanaWalletProvider;
|
|
258
|
-
_CdpSolanaWalletProvider_connection = new WeakMap(),
|
|
294
|
+
_CdpSolanaWalletProvider_connection = new WeakMap(), _CdpSolanaWalletProvider_cdp = new WeakMap(), _CdpSolanaWalletProvider_network = new WeakMap(), _CdpSolanaWalletProvider_serverAccount = new WeakMap();
|
|
@@ -307,4 +307,20 @@ describe("CdpSolanaWalletProvider", () => {
|
|
|
307
307
|
await expect(provider.nativeTransfer(invalidAddress, amount)).rejects.toThrow();
|
|
308
308
|
});
|
|
309
309
|
});
|
|
310
|
+
// =========================================================
|
|
311
|
+
// KeyPairSigner tests
|
|
312
|
+
// =========================================================
|
|
313
|
+
describe("KeyPairSigner", () => {
|
|
314
|
+
it("should handle errors when getting KeyPairSigner", async () => {
|
|
315
|
+
// Mock exportAccount to throw an error
|
|
316
|
+
mockCdpClient.solana.exportAccount = jest.fn().mockRejectedValue(new Error("Export failed"));
|
|
317
|
+
await expect(provider.getKeyPairSigner()).rejects.toThrow("Export failed");
|
|
318
|
+
});
|
|
319
|
+
it("should handle errors gracefully in isKeyPairSigner", async () => {
|
|
320
|
+
// Mock exportAccount to throw an error
|
|
321
|
+
mockCdpClient.solana.exportAccount = jest.fn().mockRejectedValue(new Error("Export failed"));
|
|
322
|
+
const isValid = await provider.isKeyPairSigner();
|
|
323
|
+
expect(isValid).toBe(false);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
310
326
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KeyPairSigner } from "@solana/kit";
|
|
1
2
|
import { SvmWalletProvider } from "./svmWalletProvider";
|
|
2
3
|
import { RpcResponseAndContext, SignatureStatus, VersionedTransaction, Connection, PublicKey, SignatureResult } from "@solana/web3.js";
|
|
3
4
|
import { Network } from "../network/types";
|
|
@@ -127,4 +128,17 @@ export declare class PrivySvmWalletProvider extends SvmWalletProvider {
|
|
|
127
128
|
* @returns The public key.
|
|
128
129
|
*/
|
|
129
130
|
getPublicKey(): PublicKey;
|
|
131
|
+
/**
|
|
132
|
+
* Sign a message.
|
|
133
|
+
*
|
|
134
|
+
* @param _ - The message to sign as a Uint8Array (unused)
|
|
135
|
+
* @returns Never - throws an error as message signing is not supported yet
|
|
136
|
+
*/
|
|
137
|
+
signMessage(_: Uint8Array): Promise<Uint8Array>;
|
|
138
|
+
/**
|
|
139
|
+
* Get the keypair signer for this wallet.
|
|
140
|
+
*
|
|
141
|
+
* @returns The KeyPairSigner
|
|
142
|
+
*/
|
|
143
|
+
getKeyPairSigner(): Promise<KeyPairSigner>;
|
|
130
144
|
}
|
|
@@ -210,6 +210,23 @@ class PrivySvmWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
210
210
|
getPublicKey() {
|
|
211
211
|
return new web3_js_1.PublicKey(__classPrivateFieldGet(this, _PrivySvmWalletProvider_address, "f"));
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Sign a message.
|
|
215
|
+
*
|
|
216
|
+
* @param _ - The message to sign as a Uint8Array (unused)
|
|
217
|
+
* @returns Never - throws an error as message signing is not supported yet
|
|
218
|
+
*/
|
|
219
|
+
async signMessage(_) {
|
|
220
|
+
throw new Error("Message signing is not supported yet for PrivySvmWalletProvider");
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get the keypair signer for this wallet.
|
|
224
|
+
*
|
|
225
|
+
* @returns The KeyPairSigner
|
|
226
|
+
*/
|
|
227
|
+
async getKeyPairSigner() {
|
|
228
|
+
throw new Error("getKeyPairSigner is not supported for PrivySvmWalletProvider");
|
|
229
|
+
}
|
|
213
230
|
}
|
|
214
231
|
exports.PrivySvmWalletProvider = PrivySvmWalletProvider;
|
|
215
232
|
_PrivySvmWalletProvider_walletId = new WeakMap(), _PrivySvmWalletProvider_address = new WeakMap(), _PrivySvmWalletProvider_authorizationPrivateKey = new WeakMap(), _PrivySvmWalletProvider_privyClient = new WeakMap(), _PrivySvmWalletProvider_connection = new WeakMap(), _PrivySvmWalletProvider_genesisHash = new WeakMap();
|
|
@@ -307,5 +307,15 @@ describe("PrivySvmWalletProvider", () => {
|
|
|
307
307
|
connection.getBalance = mockMethod;
|
|
308
308
|
await expect(provider.getBalance()).rejects.toThrow("RPC endpoint error");
|
|
309
309
|
});
|
|
310
|
+
it("should throw error when trying to get KeyPairSigner", async () => {
|
|
311
|
+
await expect(provider.getKeyPairSigner()).rejects.toThrow("getKeyPairSigner is not supported for PrivySvmWalletProvider");
|
|
312
|
+
});
|
|
313
|
+
it("should throw error when trying to convert to signer", async () => {
|
|
314
|
+
await expect(provider.toSigner()).rejects.toThrow("getKeyPairSigner is not supported for PrivySvmWalletProvider");
|
|
315
|
+
});
|
|
316
|
+
it("should return false for isKeyPairSigner", async () => {
|
|
317
|
+
const isValid = await provider.isKeyPairSigner();
|
|
318
|
+
expect(isValid).toBe(false);
|
|
319
|
+
});
|
|
310
320
|
});
|
|
311
321
|
});
|
|
@@ -2,6 +2,7 @@ import { SvmWalletProvider } from "./svmWalletProvider";
|
|
|
2
2
|
import { Network } from "../network";
|
|
3
3
|
import { Connection, PublicKey, VersionedTransaction, RpcResponseAndContext, SignatureResult, SignatureStatus, SignatureStatusConfig } from "@solana/web3.js";
|
|
4
4
|
import { SOLANA_CLUSTER, SOLANA_NETWORK_ID } from "../network/svm";
|
|
5
|
+
import { KeyPairSigner } from "@solana/kit";
|
|
5
6
|
/**
|
|
6
7
|
* SolanaKeypairWalletProvider is a wallet provider that uses a local Solana keypair.
|
|
7
8
|
*
|
|
@@ -133,6 +134,13 @@ export declare class SolanaKeypairWalletProvider extends SvmWalletProvider {
|
|
|
133
134
|
* @returns The signature
|
|
134
135
|
*/
|
|
135
136
|
nativeTransfer(to: string, value: string): Promise<string>;
|
|
137
|
+
/**
|
|
138
|
+
* Sign a message.
|
|
139
|
+
*
|
|
140
|
+
* @param _ - The message to sign as a Uint8Array (unused)
|
|
141
|
+
* @returns Never - throws an error as message signing is not supported yet
|
|
142
|
+
*/
|
|
143
|
+
signMessage(_: Uint8Array): Promise<Uint8Array>;
|
|
136
144
|
/**
|
|
137
145
|
* Request SOL tokens from the Solana faucet. This method only works on devnet and testnet networks.
|
|
138
146
|
*
|
|
@@ -140,4 +148,10 @@ export declare class SolanaKeypairWalletProvider extends SvmWalletProvider {
|
|
|
140
148
|
* @returns A Promise that resolves to the signature of the airdrop
|
|
141
149
|
*/
|
|
142
150
|
requestAirdrop(lamports: number): Promise<string>;
|
|
151
|
+
/**
|
|
152
|
+
* Get the keypair signer for this wallet.
|
|
153
|
+
*
|
|
154
|
+
* @returns The KeyPairSigner
|
|
155
|
+
*/
|
|
156
|
+
getKeyPairSigner(): Promise<KeyPairSigner>;
|
|
143
157
|
}
|
|
@@ -265,6 +265,15 @@ class SolanaKeypairWalletProvider extends svmWalletProvider_1.SvmWalletProvider
|
|
|
265
265
|
await this.waitForSignatureResult(signature);
|
|
266
266
|
return signature;
|
|
267
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Sign a message.
|
|
270
|
+
*
|
|
271
|
+
* @param _ - The message to sign as a Uint8Array (unused)
|
|
272
|
+
* @returns Never - throws an error as message signing is not supported yet
|
|
273
|
+
*/
|
|
274
|
+
async signMessage(_) {
|
|
275
|
+
throw new Error("Message signing is not supported yet for SolanaKeypairWalletProvider");
|
|
276
|
+
}
|
|
268
277
|
/**
|
|
269
278
|
* Request SOL tokens from the Solana faucet. This method only works on devnet and testnet networks.
|
|
270
279
|
*
|
|
@@ -274,6 +283,14 @@ class SolanaKeypairWalletProvider extends svmWalletProvider_1.SvmWalletProvider
|
|
|
274
283
|
async requestAirdrop(lamports) {
|
|
275
284
|
return await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").requestAirdrop(__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey, lamports);
|
|
276
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Get the keypair signer for this wallet.
|
|
288
|
+
*
|
|
289
|
+
* @returns The KeyPairSigner
|
|
290
|
+
*/
|
|
291
|
+
async getKeyPairSigner() {
|
|
292
|
+
return (0, svmWalletProvider_1.createSignerFromBytes)(__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").secretKey);
|
|
293
|
+
}
|
|
277
294
|
}
|
|
278
295
|
exports.SolanaKeypairWalletProvider = SolanaKeypairWalletProvider;
|
|
279
296
|
_SolanaKeypairWalletProvider_keypair = new WeakMap(), _SolanaKeypairWalletProvider_connection = new WeakMap(), _SolanaKeypairWalletProvider_genesisHash = new WeakMap();
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { WalletProvider } from "./walletProvider";
|
|
2
2
|
import { Connection, PublicKey, RpcResponseAndContext, SignatureStatus, SignatureStatusConfig, VersionedTransaction, SignatureResult } from "@solana/web3.js";
|
|
3
|
+
import { KeyPairSigner } from "@solana/kit";
|
|
3
4
|
/**
|
|
4
5
|
* SvmWalletProvider is the abstract base class for all Solana wallet providers (non browsers).
|
|
5
6
|
*
|
|
6
7
|
* @abstract
|
|
7
8
|
*/
|
|
8
9
|
export declare abstract class SvmWalletProvider extends WalletProvider {
|
|
10
|
+
/**
|
|
11
|
+
* Convert the wallet provider to a KeyPairSigner.
|
|
12
|
+
*
|
|
13
|
+
* @returns The KeyPairSigner instance
|
|
14
|
+
*/
|
|
15
|
+
toSigner(): Promise<KeyPairSigner>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if this wallet's signer is a valid KeyPairSigner.
|
|
18
|
+
*
|
|
19
|
+
* @returns True if the signer is a valid KeyPairSigner, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
isKeyPairSigner(): Promise<boolean>;
|
|
9
22
|
/**
|
|
10
23
|
* Get the connection instance.
|
|
11
24
|
*
|
|
@@ -53,4 +66,25 @@ export declare abstract class SvmWalletProvider extends WalletProvider {
|
|
|
53
66
|
* @returns The confirmation response
|
|
54
67
|
*/
|
|
55
68
|
abstract waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign a message.
|
|
71
|
+
*
|
|
72
|
+
* @param message - The message to sign as a Uint8Array
|
|
73
|
+
* @returns The signature as a Uint8Array
|
|
74
|
+
*/
|
|
75
|
+
abstract signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
76
|
+
/**
|
|
77
|
+
* Get the keypair for this wallet.
|
|
78
|
+
*
|
|
79
|
+
* @returns The CryptoKeyPair for KeyPairSigner compatibility
|
|
80
|
+
*/
|
|
81
|
+
abstract getKeyPairSigner(): Promise<KeyPairSigner>;
|
|
56
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a KeyPairSigner from raw bytes.
|
|
85
|
+
*
|
|
86
|
+
* @param bytes - The raw key bytes (32 bytes for private key only, 64 bytes for private + public key)
|
|
87
|
+
* @returns A KeyPairSigner instance
|
|
88
|
+
* @throws Error if the byte length is not 32 or 64
|
|
89
|
+
*/
|
|
90
|
+
export declare function createSignerFromBytes(bytes: Uint8Array): Promise<KeyPairSigner>;
|
|
@@ -2,12 +2,55 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.SvmWalletProvider = void 0;
|
|
5
|
+
exports.createSignerFromBytes = createSignerFromBytes;
|
|
5
6
|
const walletProvider_1 = require("./walletProvider");
|
|
7
|
+
const kit_1 = require("@solana/kit");
|
|
6
8
|
/**
|
|
7
9
|
* SvmWalletProvider is the abstract base class for all Solana wallet providers (non browsers).
|
|
8
10
|
*
|
|
9
11
|
* @abstract
|
|
10
12
|
*/
|
|
11
13
|
class SvmWalletProvider extends walletProvider_1.WalletProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Convert the wallet provider to a KeyPairSigner.
|
|
16
|
+
*
|
|
17
|
+
* @returns The KeyPairSigner instance
|
|
18
|
+
*/
|
|
19
|
+
async toSigner() {
|
|
20
|
+
return this.getKeyPairSigner();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if this wallet's signer is a valid KeyPairSigner.
|
|
24
|
+
*
|
|
25
|
+
* @returns True if the signer is a valid KeyPairSigner, false otherwise
|
|
26
|
+
*/
|
|
27
|
+
async isKeyPairSigner() {
|
|
28
|
+
try {
|
|
29
|
+
const signer = await this.toSigner();
|
|
30
|
+
return (0, kit_1.isKeyPairSigner)(signer);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
12
36
|
}
|
|
13
37
|
exports.SvmWalletProvider = SvmWalletProvider;
|
|
38
|
+
/**
|
|
39
|
+
* Create a KeyPairSigner from raw bytes.
|
|
40
|
+
*
|
|
41
|
+
* @param bytes - The raw key bytes (32 bytes for private key only, 64 bytes for private + public key)
|
|
42
|
+
* @returns A KeyPairSigner instance
|
|
43
|
+
* @throws Error if the byte length is not 32 or 64
|
|
44
|
+
*/
|
|
45
|
+
async function createSignerFromBytes(bytes) {
|
|
46
|
+
// generate a keypair signer from the bytes based on the byte-length
|
|
47
|
+
// 64 bytes represents concatenated private + public key
|
|
48
|
+
if (bytes.length === 64) {
|
|
49
|
+
return await (0, kit_1.createKeyPairSignerFromBytes)(bytes);
|
|
50
|
+
}
|
|
51
|
+
// 32 bytes represents only the private key
|
|
52
|
+
if (bytes.length === 32) {
|
|
53
|
+
return await (0, kit_1.createKeyPairSignerFromPrivateKeyBytes)(bytes);
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`Unexpected key length: ${bytes.length}. Expected 32 or 64 bytes.`);
|
|
56
|
+
}
|
|
@@ -52,4 +52,14 @@ describe("SvmWalletProvider", () => {
|
|
|
52
52
|
expect(getConnectionDescriptor).toBeDefined();
|
|
53
53
|
expect(typeof getConnectionDescriptor.value).toBe("function");
|
|
54
54
|
});
|
|
55
|
+
it("should have toSigner method", () => {
|
|
56
|
+
const toSignerDescriptor = Object.getOwnPropertyDescriptor(svmWalletProvider_1.SvmWalletProvider.prototype, "toSigner");
|
|
57
|
+
expect(toSignerDescriptor).toBeDefined();
|
|
58
|
+
expect(typeof toSignerDescriptor.value).toBe("function");
|
|
59
|
+
});
|
|
60
|
+
it("should have isKeyPairSigner method", () => {
|
|
61
|
+
const isKeyPairSignerDescriptor = Object.getOwnPropertyDescriptor(svmWalletProvider_1.SvmWalletProvider.prototype, "isKeyPairSigner");
|
|
62
|
+
expect(isKeyPairSignerDescriptor).toBeDefined();
|
|
63
|
+
expect(typeof isKeyPairSignerDescriptor.value).toBe("function");
|
|
64
|
+
});
|
|
55
65
|
});
|
|
@@ -43,7 +43,7 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
43
43
|
* @param message - The message to sign.
|
|
44
44
|
* @returns The signed message.
|
|
45
45
|
*/
|
|
46
|
-
signMessage(message: string): Promise<`0x${string}`>;
|
|
46
|
+
signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
|
|
47
47
|
/**
|
|
48
48
|
* Signs a typed data object.
|
|
49
49
|
*
|
|
@@ -71,7 +71,11 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
71
71
|
if (!account) {
|
|
72
72
|
throw new Error("Account not found");
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
const _message = typeof message === "string" ? ((0, viem_1.isHex)(message) ? message : (0, viem_1.toHex)(message)) : message;
|
|
75
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").signMessage({
|
|
76
|
+
account,
|
|
77
|
+
message: { raw: _message },
|
|
78
|
+
});
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
81
|
* Signs a typed data object.
|
|
@@ -104,6 +104,8 @@ jest.mock("viem", () => {
|
|
|
104
104
|
fromHex: jest.fn(),
|
|
105
105
|
formatEther: jest.fn(),
|
|
106
106
|
privateKeyToAccount: jest.fn(),
|
|
107
|
+
isHex: jest.fn(value => typeof value === "string" && value.startsWith("0x")),
|
|
108
|
+
toHex: jest.fn(value => `0x${value}`),
|
|
107
109
|
};
|
|
108
110
|
});
|
|
109
111
|
jest.mock("viem/accounts", () => {
|
|
@@ -222,7 +224,16 @@ describe("ViemWalletProvider", () => {
|
|
|
222
224
|
const signature = await provider.signMessage(MOCK_MESSAGE);
|
|
223
225
|
expect(mockWalletClient.signMessage).toHaveBeenCalledWith({
|
|
224
226
|
account: mockWalletClient.account,
|
|
225
|
-
message: MOCK_MESSAGE,
|
|
227
|
+
message: { raw: `0x${MOCK_MESSAGE}` },
|
|
228
|
+
});
|
|
229
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
230
|
+
});
|
|
231
|
+
it("should sign a hex message", async () => {
|
|
232
|
+
const hexMessage = "0x48656c6c6f2c20576f726c6421"; // "Hello, World!" in hex
|
|
233
|
+
const signature = await provider.signMessage(hexMessage);
|
|
234
|
+
expect(mockWalletClient.signMessage).toHaveBeenCalledWith({
|
|
235
|
+
account: mockWalletClient.account,
|
|
236
|
+
message: { raw: hexMessage },
|
|
226
237
|
});
|
|
227
238
|
expect(signature).toBe(MOCK_SIGNATURE);
|
|
228
239
|
});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@coinbase/agentkit",
|
|
3
3
|
"description": "Coinbase AgentKit core primitives",
|
|
4
4
|
"repository": "https://github.com/coinbase/agentkit",
|
|
5
|
-
"version": "0.0.0-nightly-
|
|
5
|
+
"version": "0.0.0-nightly-20251001210424",
|
|
6
6
|
"author": "Coinbase Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@across-protocol/app-sdk": "^0.2.0",
|
|
26
26
|
"@alloralabs/allora-sdk": "^0.1.0",
|
|
27
|
+
"@base-org/account": "^2.2.0",
|
|
27
28
|
"@coinbase/cdp-sdk": "^1.38.0",
|
|
28
29
|
"@coinbase/coinbase-sdk": "^0.20.0",
|
|
29
30
|
"@coinbase/x402": "^0.6.3",
|
|
30
31
|
"@jup-ag/api": "^6.0.39",
|
|
31
32
|
"@privy-io/public-api": "2.18.5",
|
|
32
33
|
"@privy-io/server-auth": "1.18.4",
|
|
34
|
+
"@solana/kit": "^2.1.1",
|
|
33
35
|
"@solana/spl-token": "^0.4.12",
|
|
34
36
|
"@solana/web3.js": "^1.98.1",
|
|
35
37
|
"@zerodev/ecdsa-validator": "^5.4.5",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"md5": "^2.3.0",
|
|
47
49
|
"opensea-js": "^7.1.18",
|
|
48
50
|
"reflect-metadata": "^0.2.2",
|
|
51
|
+
"@ensofinance/sdk": "^2.0.6",
|
|
49
52
|
"twitter-api-v2": "^1.18.2",
|
|
50
53
|
"viem": "^2.22.16",
|
|
51
54
|
"x402": "^0.6.0",
|