@coinbase/agentkit 0.1.2 → 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 +319 -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 +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/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 +14 -7
- 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 +22 -3
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/package.json +4 -1
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,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,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 {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _PrivyWalletProvider_walletId, _PrivyWalletProvider_authorizationPrivateKey;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PrivyWalletProvider = void 0;
|
|
16
|
+
const server_auth_1 = require("@privy-io/server-auth");
|
|
17
|
+
const viem_1 = require("@privy-io/server-auth/viem");
|
|
18
|
+
const viemWalletProvider_1 = require("./viemWalletProvider");
|
|
19
|
+
const viem_2 = require("viem");
|
|
20
|
+
const network_1 = require("../network/network");
|
|
21
|
+
/**
|
|
22
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
23
|
+
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
24
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
25
|
+
*/
|
|
26
|
+
class PrivyWalletProvider extends viemWalletProvider_1.ViemWalletProvider {
|
|
27
|
+
/**
|
|
28
|
+
* Private constructor to enforce use of factory method.
|
|
29
|
+
*
|
|
30
|
+
* @param walletClient - The Viem wallet client instance
|
|
31
|
+
* @param config - The configuration options for the Privy wallet
|
|
32
|
+
*/
|
|
33
|
+
constructor(walletClient, config) {
|
|
34
|
+
super(walletClient);
|
|
35
|
+
_PrivyWalletProvider_walletId.set(this, void 0);
|
|
36
|
+
_PrivyWalletProvider_authorizationPrivateKey.set(this, void 0);
|
|
37
|
+
__classPrivateFieldSet(this, _PrivyWalletProvider_walletId, config.walletId, "f"); // Now guaranteed to exist
|
|
38
|
+
__classPrivateFieldSet(this, _PrivyWalletProvider_authorizationPrivateKey, config.authorizationPrivateKey, "f");
|
|
39
|
+
}
|
|
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 async configureWithWallet(config) {
|
|
57
|
+
const privy = new server_auth_1.PrivyClient(config.appId, config.appSecret, {
|
|
58
|
+
walletApi: config.authorizationPrivateKey
|
|
59
|
+
? {
|
|
60
|
+
authorizationPrivateKey: config.authorizationPrivateKey,
|
|
61
|
+
}
|
|
62
|
+
: undefined,
|
|
63
|
+
});
|
|
64
|
+
let walletId;
|
|
65
|
+
let address;
|
|
66
|
+
if (!config.walletId) {
|
|
67
|
+
if (config.authorizationPrivateKey && !config.authorizationKeyId) {
|
|
68
|
+
throw new Error("authorizationKeyId is required when creating a new wallet with an authorization key, this can be found in your Privy Dashboard");
|
|
69
|
+
}
|
|
70
|
+
if (config.authorizationKeyId && !config.authorizationPrivateKey) {
|
|
71
|
+
throw new Error("authorizationPrivateKey is required when creating a new wallet with an authorizationKeyId. " +
|
|
72
|
+
"If you don't have it, you can create a new one in your Privy Dashboard, or delete the authorization key.");
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const wallet = await privy.walletApi.create({
|
|
76
|
+
chainType: "ethereum",
|
|
77
|
+
authorizationKeyIds: config.authorizationKeyId ? [config.authorizationKeyId] : undefined,
|
|
78
|
+
});
|
|
79
|
+
walletId = wallet.id;
|
|
80
|
+
address = wallet.address;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(error);
|
|
84
|
+
if (error instanceof Error &&
|
|
85
|
+
error.message.includes("Missing `privy-authorization-signature` header")) {
|
|
86
|
+
// Providing a more informative error message, see context: https://github.com/coinbase/agentkit/pull/242#discussion_r1956428617
|
|
87
|
+
throw new Error("Privy error: you have an authorization key on your account which can create and modify wallets, please delete this key or pass it to the PrivyWalletProvider to create a new wallet");
|
|
88
|
+
}
|
|
89
|
+
throw new Error("Failed to create wallet");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
walletId = config.walletId;
|
|
94
|
+
const wallet = await privy.walletApi.getWallet({ id: walletId });
|
|
95
|
+
if (!wallet) {
|
|
96
|
+
throw new Error(`Wallet with ID ${walletId} not found`);
|
|
97
|
+
}
|
|
98
|
+
address = wallet.address;
|
|
99
|
+
}
|
|
100
|
+
const account = await (0, viem_1.createViemAccount)({
|
|
101
|
+
walletId,
|
|
102
|
+
address,
|
|
103
|
+
privy,
|
|
104
|
+
});
|
|
105
|
+
const chainId = config.chainId || "84532";
|
|
106
|
+
const chain = (0, network_1.getChain)(chainId);
|
|
107
|
+
if (!chain) {
|
|
108
|
+
throw new Error(`Chain with ID ${chainId} not found`);
|
|
109
|
+
}
|
|
110
|
+
const walletClient = (0, viem_2.createWalletClient)({
|
|
111
|
+
account,
|
|
112
|
+
chain,
|
|
113
|
+
transport: (0, viem_2.http)(),
|
|
114
|
+
});
|
|
115
|
+
return new PrivyWalletProvider(walletClient, { ...config, walletId });
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the name of the wallet provider.
|
|
119
|
+
*
|
|
120
|
+
* @returns The string identifier for this wallet provider
|
|
121
|
+
*/
|
|
122
|
+
getName() {
|
|
123
|
+
return "privy_wallet_provider";
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Exports the wallet data.
|
|
127
|
+
*
|
|
128
|
+
* @returns The wallet data
|
|
129
|
+
*/
|
|
130
|
+
exportWallet() {
|
|
131
|
+
return {
|
|
132
|
+
walletId: __classPrivateFieldGet(this, _PrivyWalletProvider_walletId, "f"),
|
|
133
|
+
authorizationPrivateKey: __classPrivateFieldGet(this, _PrivyWalletProvider_authorizationPrivateKey, "f"),
|
|
134
|
+
chainId: this.getNetwork().chainId,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.PrivyWalletProvider = PrivyWalletProvider;
|
|
139
|
+
_PrivyWalletProvider_walletId = new WeakMap(), _PrivyWalletProvider_authorizationPrivateKey = new WeakMap();
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { SvmWalletProvider } from "./svmWalletProvider";
|
|
2
|
+
import { Network } from "../network";
|
|
3
|
+
import { Connection, PublicKey, VersionedTransaction, RpcResponseAndContext, SignatureResult, SignatureStatus, SignatureStatusConfig } from "@solana/web3.js";
|
|
4
|
+
import { SOLANA_CLUSTER, SOLANA_NETWORK_ID } from "../network/svm";
|
|
5
|
+
/**
|
|
6
|
+
* SolanaKeypairWalletProvider is a wallet provider that uses a local Solana keypair.
|
|
7
|
+
*
|
|
8
|
+
* @augments SvmWalletProvider
|
|
9
|
+
*/
|
|
10
|
+
export declare class SolanaKeypairWalletProvider extends SvmWalletProvider {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new SolanaKeypairWalletProvider
|
|
14
|
+
*
|
|
15
|
+
* @param args - Configuration arguments
|
|
16
|
+
* @param args.keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
17
|
+
* @param args.rpcUrl - URL of the Solana RPC endpoint
|
|
18
|
+
* @param args.genesisHash - The genesis hash of the network
|
|
19
|
+
*/
|
|
20
|
+
constructor({ keypair, rpcUrl, genesisHash, }: {
|
|
21
|
+
keypair: Uint8Array | string;
|
|
22
|
+
rpcUrl: string;
|
|
23
|
+
genesisHash: string;
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Get the default RPC URL for a Solana cluster
|
|
27
|
+
*
|
|
28
|
+
* @param cluster - The cluster to get the RPC URL for
|
|
29
|
+
* @returns The RPC URL for the cluster
|
|
30
|
+
*/
|
|
31
|
+
static urlForCluster(cluster: SOLANA_CLUSTER): string;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new SolanaKeypairWalletProvider from an SVM networkId and a keypair
|
|
34
|
+
*
|
|
35
|
+
* @param networkId - The SVM networkId
|
|
36
|
+
* @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
37
|
+
* @returns The new SolanaKeypairWalletProvider
|
|
38
|
+
*/
|
|
39
|
+
static fromNetwork<T extends SolanaKeypairWalletProvider>(networkId: SOLANA_NETWORK_ID, keypair: Uint8Array | string): Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Create a new SolanaKeypairWalletProvider from an RPC URL and a keypair
|
|
42
|
+
*
|
|
43
|
+
* @param rpcUrl - The URL of the Solana RPC endpoint
|
|
44
|
+
* @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
45
|
+
* @returns The new SolanaKeypairWalletProvider
|
|
46
|
+
*/
|
|
47
|
+
static fromRpcUrl<T extends SolanaKeypairWalletProvider>(rpcUrl: string, keypair: Uint8Array | string): Promise<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new SolanaKeypairWalletProvider from a Connection and a keypair
|
|
50
|
+
*
|
|
51
|
+
* @param connection - The Connection to use
|
|
52
|
+
* @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
53
|
+
* @returns The new SolanaKeypairWalletProvider
|
|
54
|
+
*/
|
|
55
|
+
static fromConnection<T extends SolanaKeypairWalletProvider>(connection: Connection, keypair: Uint8Array | string): Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Get the connection instance
|
|
58
|
+
*
|
|
59
|
+
* @returns The Solana connection instance
|
|
60
|
+
*/
|
|
61
|
+
getConnection(): Connection;
|
|
62
|
+
/**
|
|
63
|
+
* Get the public key of the wallet
|
|
64
|
+
*
|
|
65
|
+
* @returns The wallet's public key
|
|
66
|
+
*/
|
|
67
|
+
getPublicKey(): PublicKey;
|
|
68
|
+
/**
|
|
69
|
+
* Get the address of the wallet
|
|
70
|
+
*
|
|
71
|
+
* @returns The base58 encoded address of the wallet
|
|
72
|
+
*/
|
|
73
|
+
getAddress(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Get the network
|
|
76
|
+
*
|
|
77
|
+
* @returns The network
|
|
78
|
+
*/
|
|
79
|
+
getNetwork(): Network;
|
|
80
|
+
/**
|
|
81
|
+
* Sign a transaction
|
|
82
|
+
*
|
|
83
|
+
* @param transaction - The transaction to sign
|
|
84
|
+
* @returns The signed transaction
|
|
85
|
+
*/
|
|
86
|
+
signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
87
|
+
/**
|
|
88
|
+
* Send a transaction
|
|
89
|
+
*
|
|
90
|
+
* @param transaction - The transaction to send
|
|
91
|
+
* @returns The signature
|
|
92
|
+
*/
|
|
93
|
+
sendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Sign and send a transaction
|
|
96
|
+
*
|
|
97
|
+
* @param transaction - The transaction to sign and send
|
|
98
|
+
* @returns The signature
|
|
99
|
+
*/
|
|
100
|
+
signAndSendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Get the status of a transaction
|
|
103
|
+
*
|
|
104
|
+
* @param signature - The signature
|
|
105
|
+
* @param options - The options for the status
|
|
106
|
+
* @returns The status
|
|
107
|
+
*/
|
|
108
|
+
getSignatureStatus(signature: string, options?: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus | null>>;
|
|
109
|
+
/**
|
|
110
|
+
* Wait for signature receipt
|
|
111
|
+
*
|
|
112
|
+
* @param signature - The signature
|
|
113
|
+
* @returns The confirmation response
|
|
114
|
+
*/
|
|
115
|
+
waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
116
|
+
/**
|
|
117
|
+
* Get the name of the wallet provider
|
|
118
|
+
*
|
|
119
|
+
* @returns The name of the wallet provider
|
|
120
|
+
*/
|
|
121
|
+
getName(): string;
|
|
122
|
+
/**
|
|
123
|
+
* Get the balance of the wallet
|
|
124
|
+
*
|
|
125
|
+
* @returns The balance of the wallet
|
|
126
|
+
*/
|
|
127
|
+
getBalance(): Promise<bigint>;
|
|
128
|
+
/**
|
|
129
|
+
* Transfer SOL from the wallet to another address
|
|
130
|
+
*
|
|
131
|
+
* @param to - The base58 encoded address to transfer the SOL to
|
|
132
|
+
* @param value - The amount of SOL to transfer (as a decimal string, e.g. "0.0001")
|
|
133
|
+
* @returns The signature
|
|
134
|
+
*/
|
|
135
|
+
nativeTransfer(to: string, value: string): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Request SOL tokens from the Solana faucet. This method only works on devnet and testnet networks.
|
|
138
|
+
*
|
|
139
|
+
* @param lamports - The amount of lamports (1 SOL = 1,000,000,000 lamports) to request from the faucet
|
|
140
|
+
* @returns A Promise that resolves to the signature of the airdrop
|
|
141
|
+
*/
|
|
142
|
+
requestAirdrop(lamports: number): Promise<string>;
|
|
143
|
+
}
|