@coinbase/agentkit 0.0.0-nightly-20250328174338
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 +827 -0
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/actionDecorator.d.ts +69 -0
- package/dist/action-providers/actionDecorator.js +96 -0
- package/dist/action-providers/actionProvider.d.ts +48 -0
- package/dist/action-providers/actionProvider.js +62 -0
- 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/allora/alloraActionProvider.d.ts +44 -0
- package/dist/action-providers/allora/alloraActionProvider.js +195 -0
- package/dist/action-providers/allora/alloraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/allora/alloraActionProvider.test.js +109 -0
- package/dist/action-providers/allora/index.d.ts +2 -0
- package/dist/action-providers/allora/index.js +18 -0
- package/dist/action-providers/allora/schemas.d.ts +28 -0
- package/dist/action-providers/allora/schemas.js +30 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +30 -0
- package/dist/action-providers/basename/basenameActionProvider.js +109 -0
- package/dist/action-providers/basename/basenameActionProvider.test.d.ts +1 -0
- package/dist/action-providers/basename/basenameActionProvider.test.js +146 -0
- package/dist/action-providers/basename/constants.d.ts +52 -0
- package/dist/action-providers/basename/constants.js +81 -0
- package/dist/action-providers/basename/index.d.ts +2 -0
- package/dist/action-providers/basename/index.js +18 -0
- package/dist/action-providers/basename/schemas.d.ts +14 -0
- package/dist/action-providers/basename/schemas.js +14 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.js +128 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +58 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.js +224 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +267 -0
- package/dist/action-providers/cdp/constants.d.ts +31 -0
- package/dist/action-providers/cdp/constants.js +34 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +19 -0
- package/dist/action-providers/cdp/schemas.d.ts +91 -0
- package/dist/action-providers/cdp/schemas.js +77 -0
- package/dist/action-providers/compound/compoundActionProvider.d.ts +67 -0
- package/dist/action-providers/compound/compoundActionProvider.js +365 -0
- package/dist/action-providers/compound/compoundActionProvider.test.d.ts +1 -0
- package/dist/action-providers/compound/compoundActionProvider.test.js +353 -0
- package/dist/action-providers/compound/constants.d.ts +180 -0
- package/dist/action-providers/compound/constants.js +129 -0
- package/dist/action-providers/compound/index.d.ts +1 -0
- package/dist/action-providers/compound/index.js +17 -0
- package/dist/action-providers/compound/schemas.d.ts +57 -0
- package/dist/action-providers/compound/schemas.js +58 -0
- package/dist/action-providers/compound/utils.d.ts +95 -0
- package/dist/action-providers/compound/utils.js +353 -0
- package/dist/action-providers/customActionProvider.d.ts +30 -0
- package/dist/action-providers/customActionProvider.js +66 -0
- package/dist/action-providers/defillama/constants.d.ts +8 -0
- package/dist/action-providers/defillama/constants.js +11 -0
- package/dist/action-providers/defillama/defillamaActionProvider.d.ts +54 -0
- package/dist/action-providers/defillama/defillamaActionProvider.js +180 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.js +114 -0
- package/dist/action-providers/defillama/index.d.ts +1 -0
- package/dist/action-providers/defillama/index.js +17 -0
- package/dist/action-providers/defillama/schemas.d.ts +34 -0
- package/dist/action-providers/defillama/schemas.js +34 -0
- package/dist/action-providers/defillama/types.d.ts +73 -0
- package/dist/action-providers/defillama/types.js +2 -0
- package/dist/action-providers/defillama/utils.d.ts +10 -0
- package/dist/action-providers/defillama/utils.js +87 -0
- package/dist/action-providers/defillama/utils.test.d.ts +1 -0
- package/dist/action-providers/defillama/utils.test.js +124 -0
- package/dist/action-providers/erc20/constants.d.ts +137 -0
- package/dist/action-providers/erc20/constants.js +202 -0
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +38 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +142 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +131 -0
- package/dist/action-providers/erc20/index.d.ts +1 -0
- package/dist/action-providers/erc20/index.js +17 -0
- package/dist/action-providers/erc20/schemas.d.ts +27 -0
- package/dist/action-providers/erc20/schemas.js +26 -0
- package/dist/action-providers/erc721/constants.d.ts +232 -0
- package/dist/action-providers/erc721/constants.js +298 -0
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +46 -0
- package/dist/action-providers/erc721/erc721ActionProvider.js +164 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.js +137 -0
- package/dist/action-providers/erc721/index.d.ts +1 -0
- package/dist/action-providers/erc721/index.js +17 -0
- package/dist/action-providers/erc721/schemas.d.ts +46 -0
- package/dist/action-providers/erc721/schemas.js +44 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +57 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.js +142 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +151 -0
- package/dist/action-providers/farcaster/index.d.ts +2 -0
- package/dist/action-providers/farcaster/index.js +18 -0
- package/dist/action-providers/farcaster/schemas.d.ts +15 -0
- package/dist/action-providers/farcaster/schemas.js +20 -0
- package/dist/action-providers/index.d.ts +24 -0
- package/dist/action-providers/index.js +40 -0
- package/dist/action-providers/jupiter/index.d.ts +1 -0
- package/dist/action-providers/jupiter/index.js +17 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.d.ts +36 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +115 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +146 -0
- package/dist/action-providers/jupiter/schemas.d.ts +20 -0
- package/dist/action-providers/jupiter/schemas.js +20 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- 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/constants.d.ts +16 -0
- package/dist/action-providers/morpho/constants.js +27 -0
- package/dist/action-providers/morpho/index.d.ts +2 -0
- package/dist/action-providers/morpho/index.js +18 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.js +154 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.d.ts +1 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.js +128 -0
- package/dist/action-providers/morpho/schemas.d.ts +36 -0
- package/dist/action-providers/morpho/schemas.js +47 -0
- package/dist/action-providers/opensea/index.d.ts +1 -0
- package/dist/action-providers/opensea/index.js +17 -0
- package/dist/action-providers/opensea/openseaActionProvider.d.ts +59 -0
- package/dist/action-providers/opensea/openseaActionProvider.js +146 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.js +201 -0
- package/dist/action-providers/opensea/schemas.d.ts +30 -0
- package/dist/action-providers/opensea/schemas.js +33 -0
- package/dist/action-providers/opensea/utils.d.ts +12 -0
- package/dist/action-providers/opensea/utils.js +47 -0
- package/dist/action-providers/pyth/index.d.ts +2 -0
- package/dist/action-providers/pyth/index.js +18 -0
- package/dist/action-providers/pyth/pythActionProvider.d.ts +33 -0
- package/dist/action-providers/pyth/pythActionProvider.js +121 -0
- 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/pyth/schemas.d.ts +21 -0
- package/dist/action-providers/pyth/schemas.js +20 -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 +30 -0
- package/dist/action-providers/spl/schemas.js +26 -0
- package/dist/action-providers/spl/splActionProvider.d.ts +45 -0
- package/dist/action-providers/spl/splActionProvider.js +173 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +300 -0
- package/dist/action-providers/twitter/index.d.ts +2 -0
- package/dist/action-providers/twitter/index.js +18 -0
- package/dist/action-providers/twitter/schemas.d.ts +38 -0
- package/dist/action-providers/twitter/schemas.js +44 -0
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +82 -0
- package/dist/action-providers/twitter/twitterActionProvider.js +204 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.js +185 -0
- package/dist/action-providers/wallet/index.d.ts +1 -0
- package/dist/action-providers/wallet/index.js +17 -0
- package/dist/action-providers/wallet/schemas.d.ts +19 -0
- package/dist/action-providers/wallet/schemas.js +19 -0
- package/dist/action-providers/wallet/walletActionProvider.d.ts +44 -0
- package/dist/action-providers/wallet/walletActionProvider.js +140 -0
- package/dist/action-providers/wallet/walletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wallet/walletActionProvider.test.js +194 -0
- package/dist/action-providers/weth/constants.d.ts +19 -0
- package/dist/action-providers/weth/constants.js +29 -0
- package/dist/action-providers/weth/index.d.ts +1 -0
- package/dist/action-providers/weth/index.js +17 -0
- package/dist/action-providers/weth/schemas.d.ts +8 -0
- package/dist/action-providers/weth/schemas.js +10 -0
- package/dist/action-providers/weth/wethActionProvider.d.ts +30 -0
- package/dist/action-providers/weth/wethActionProvider.js +89 -0
- package/dist/action-providers/weth/wethActionProvider.test.d.ts +1 -0
- package/dist/action-providers/weth/wethActionProvider.test.js +92 -0
- package/dist/action-providers/wow/constants.d.ts +15 -0
- package/dist/action-providers/wow/constants.js +844 -0
- package/dist/action-providers/wow/index.d.ts +2 -0
- package/dist/action-providers/wow/index.js +18 -0
- package/dist/action-providers/wow/schemas.d.ts +43 -0
- package/dist/action-providers/wow/schemas.js +47 -0
- package/dist/action-providers/wow/uniswap/constants.d.ts +3 -0
- package/dist/action-providers/wow/uniswap/constants.js +100 -0
- package/dist/action-providers/wow/uniswap/utils.d.ts +82 -0
- package/dist/action-providers/wow/uniswap/utils.js +226 -0
- package/dist/action-providers/wow/utils.d.ts +27 -0
- package/dist/action-providers/wow/utils.js +63 -0
- package/dist/action-providers/wow/wowActionProvider.d.ts +46 -0
- package/dist/action-providers/wow/wowActionProvider.js +223 -0
- package/dist/action-providers/wow/wowActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wow/wowActionProvider.test.js +291 -0
- package/dist/agentkit.d.ts +44 -0
- package/dist/agentkit.js +68 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +17 -0
- package/dist/analytics/sendAnalyticsEvent.d.ts +31 -0
- package/dist/analytics/sendAnalyticsEvent.js +52 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/network/index.d.ts +3 -0
- package/dist/network/index.js +19 -0
- package/dist/network/network.d.ts +20 -0
- package/dist/network/network.js +86 -0
- package/dist/network/svm.d.ts +15 -0
- package/dist/network/svm.js +38 -0
- package/dist/network/types.d.ts +17 -0
- package/dist/network/types.js +2 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +57 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +50 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +246 -0
- package/dist/wallet-providers/cdpWalletProvider.js +421 -0
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +701 -0
- package/dist/wallet-providers/evmWalletProvider.d.ts +51 -0
- package/dist/wallet-providers/evmWalletProvider.js +14 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +10 -0
- package/dist/wallet-providers/index.js +26 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +40 -0
- package/dist/wallet-providers/privyShared.js +49 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +35 -0
- package/dist/wallet-providers/privyWalletProvider.js +39 -0
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.d.ts +177 -0
- package/dist/wallet-providers/smartWalletProvider.js +303 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -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 +218 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
- package/dist/wallet-providers/svmWalletProvider.js +13 -0
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +103 -0
- package/dist/wallet-providers/viemWalletProvider.js +206 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.d.ts +48 -0
- package/dist/wallet-providers/walletProvider.js +41 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +83 -0
|
@@ -0,0 +1,280 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _SolanaKeypairWalletProvider_keypair, _SolanaKeypairWalletProvider_connection, _SolanaKeypairWalletProvider_genesisHash;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SolanaKeypairWalletProvider = void 0;
|
|
19
|
+
const svmWalletProvider_1 = require("./svmWalletProvider");
|
|
20
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
21
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
22
|
+
const svm_1 = require("../network/svm");
|
|
23
|
+
/**
|
|
24
|
+
* SolanaKeypairWalletProvider is a wallet provider that uses a local Solana keypair.
|
|
25
|
+
*
|
|
26
|
+
* @augments SvmWalletProvider
|
|
27
|
+
*/
|
|
28
|
+
class SolanaKeypairWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new SolanaKeypairWalletProvider
|
|
31
|
+
*
|
|
32
|
+
* @param args - Configuration arguments
|
|
33
|
+
* @param args.keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
34
|
+
* @param args.rpcUrl - URL of the Solana RPC endpoint
|
|
35
|
+
* @param args.genesisHash - The genesis hash of the network
|
|
36
|
+
*/
|
|
37
|
+
constructor({ keypair, rpcUrl, genesisHash, }) {
|
|
38
|
+
super();
|
|
39
|
+
_SolanaKeypairWalletProvider_keypair.set(this, void 0);
|
|
40
|
+
_SolanaKeypairWalletProvider_connection.set(this, void 0);
|
|
41
|
+
_SolanaKeypairWalletProvider_genesisHash.set(this, void 0);
|
|
42
|
+
__classPrivateFieldSet(this, _SolanaKeypairWalletProvider_keypair, typeof keypair === "string"
|
|
43
|
+
? web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(keypair))
|
|
44
|
+
: web3_js_1.Keypair.fromSecretKey(keypair), "f");
|
|
45
|
+
__classPrivateFieldSet(this, _SolanaKeypairWalletProvider_connection, new web3_js_1.Connection(rpcUrl), "f");
|
|
46
|
+
if (genesisHash in svm_1.SOLANA_NETWORKS) {
|
|
47
|
+
__classPrivateFieldSet(this, _SolanaKeypairWalletProvider_genesisHash, genesisHash, "f");
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error(`Unknown network with genesis hash: ${genesisHash}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the default RPC URL for a Solana cluster
|
|
55
|
+
*
|
|
56
|
+
* @param cluster - The cluster to get the RPC URL for
|
|
57
|
+
* @returns The RPC URL for the cluster
|
|
58
|
+
*/
|
|
59
|
+
static urlForCluster(cluster) {
|
|
60
|
+
if (cluster in svm_1.SOLANA_NETWORKS) {
|
|
61
|
+
switch (cluster) {
|
|
62
|
+
case svm_1.SOLANA_MAINNET_GENESIS_BLOCK_HASH:
|
|
63
|
+
return (0, web3_js_1.clusterApiUrl)("mainnet-beta");
|
|
64
|
+
case svm_1.SOLANA_TESTNET_GENESIS_BLOCK_HASH:
|
|
65
|
+
return (0, web3_js_1.clusterApiUrl)("testnet");
|
|
66
|
+
case svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH:
|
|
67
|
+
return (0, web3_js_1.clusterApiUrl)("devnet");
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(`Unknown cluster: ${cluster}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(`Unknown cluster: ${cluster}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a new SolanaKeypairWalletProvider from an SVM networkId and a keypair
|
|
78
|
+
*
|
|
79
|
+
* @param networkId - The SVM networkId
|
|
80
|
+
* @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
81
|
+
* @returns The new SolanaKeypairWalletProvider
|
|
82
|
+
*/
|
|
83
|
+
static async fromNetwork(networkId, keypair) {
|
|
84
|
+
let genesisHash;
|
|
85
|
+
switch (networkId) {
|
|
86
|
+
case svm_1.SOLANA_MAINNET_NETWORK_ID:
|
|
87
|
+
genesisHash = svm_1.SOLANA_MAINNET_GENESIS_BLOCK_HASH;
|
|
88
|
+
break;
|
|
89
|
+
case svm_1.SOLANA_DEVNET_NETWORK_ID:
|
|
90
|
+
genesisHash = svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH;
|
|
91
|
+
break;
|
|
92
|
+
case svm_1.SOLANA_TESTNET_NETWORK_ID:
|
|
93
|
+
genesisHash = svm_1.SOLANA_TESTNET_GENESIS_BLOCK_HASH;
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
throw new Error(`${networkId} is not a valid SVM networkId`);
|
|
97
|
+
}
|
|
98
|
+
const rpcUrl = this.urlForCluster(genesisHash);
|
|
99
|
+
return await this.fromRpcUrl(rpcUrl, keypair);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a new SolanaKeypairWalletProvider from an RPC URL and a keypair
|
|
103
|
+
*
|
|
104
|
+
* @param rpcUrl - The URL of the Solana RPC endpoint
|
|
105
|
+
* @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
106
|
+
* @returns The new SolanaKeypairWalletProvider
|
|
107
|
+
*/
|
|
108
|
+
static async fromRpcUrl(rpcUrl, keypair) {
|
|
109
|
+
const connection = new web3_js_1.Connection(rpcUrl);
|
|
110
|
+
return await this.fromConnection(connection, keypair);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create a new SolanaKeypairWalletProvider from a Connection and a keypair
|
|
114
|
+
*
|
|
115
|
+
* @param connection - The Connection to use
|
|
116
|
+
* @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
|
|
117
|
+
* @returns The new SolanaKeypairWalletProvider
|
|
118
|
+
*/
|
|
119
|
+
static async fromConnection(connection, keypair) {
|
|
120
|
+
const genesisHash = await connection.getGenesisHash();
|
|
121
|
+
return new SolanaKeypairWalletProvider({
|
|
122
|
+
keypair,
|
|
123
|
+
rpcUrl: connection.rpcEndpoint,
|
|
124
|
+
genesisHash: genesisHash,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the connection instance
|
|
129
|
+
*
|
|
130
|
+
* @returns The Solana connection instance
|
|
131
|
+
*/
|
|
132
|
+
getConnection() {
|
|
133
|
+
return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f");
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get the public key of the wallet
|
|
137
|
+
*
|
|
138
|
+
* @returns The wallet's public key
|
|
139
|
+
*/
|
|
140
|
+
getPublicKey() {
|
|
141
|
+
return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get the address of the wallet
|
|
145
|
+
*
|
|
146
|
+
* @returns The base58 encoded address of the wallet
|
|
147
|
+
*/
|
|
148
|
+
getAddress() {
|
|
149
|
+
return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey.toBase58();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the network
|
|
153
|
+
*
|
|
154
|
+
* @returns The network
|
|
155
|
+
*/
|
|
156
|
+
getNetwork() {
|
|
157
|
+
return svm_1.SOLANA_NETWORKS[__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_genesisHash, "f")];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Sign a transaction
|
|
161
|
+
*
|
|
162
|
+
* @param transaction - The transaction to sign
|
|
163
|
+
* @returns The signed transaction
|
|
164
|
+
*/
|
|
165
|
+
async signTransaction(transaction) {
|
|
166
|
+
transaction.sign([__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f")]);
|
|
167
|
+
return transaction;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Send a transaction
|
|
171
|
+
*
|
|
172
|
+
* @param transaction - The transaction to send
|
|
173
|
+
* @returns The signature
|
|
174
|
+
*/
|
|
175
|
+
async sendTransaction(transaction) {
|
|
176
|
+
const signature = await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").sendTransaction(transaction);
|
|
177
|
+
await this.waitForSignatureResult(signature);
|
|
178
|
+
return signature;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Sign and send a transaction
|
|
182
|
+
*
|
|
183
|
+
* @param transaction - The transaction to sign and send
|
|
184
|
+
* @returns The signature
|
|
185
|
+
*/
|
|
186
|
+
async signAndSendTransaction(transaction) {
|
|
187
|
+
const signedTransaction = await this.signTransaction(transaction);
|
|
188
|
+
return this.sendTransaction(signedTransaction);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get the status of a transaction
|
|
192
|
+
*
|
|
193
|
+
* @param signature - The signature
|
|
194
|
+
* @param options - The options for the status
|
|
195
|
+
* @returns The status
|
|
196
|
+
*/
|
|
197
|
+
async getSignatureStatus(signature, options) {
|
|
198
|
+
return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getSignatureStatus(signature, options);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Wait for signature receipt
|
|
202
|
+
*
|
|
203
|
+
* @param signature - The signature
|
|
204
|
+
* @returns The confirmation response
|
|
205
|
+
*/
|
|
206
|
+
async waitForSignatureResult(signature) {
|
|
207
|
+
const { blockhash, lastValidBlockHeight } = await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getLatestBlockhash();
|
|
208
|
+
return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").confirmTransaction({
|
|
209
|
+
signature: signature,
|
|
210
|
+
lastValidBlockHeight,
|
|
211
|
+
blockhash,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get the name of the wallet provider
|
|
216
|
+
*
|
|
217
|
+
* @returns The name of the wallet provider
|
|
218
|
+
*/
|
|
219
|
+
getName() {
|
|
220
|
+
return "solana_keypair_wallet_provider";
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get the balance of the wallet
|
|
224
|
+
*
|
|
225
|
+
* @returns The balance of the wallet
|
|
226
|
+
*/
|
|
227
|
+
getBalance() {
|
|
228
|
+
return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getBalance(__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey).then(balance => BigInt(balance));
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Transfer SOL from the wallet to another address
|
|
232
|
+
*
|
|
233
|
+
* @param to - The base58 encoded address to transfer the SOL to
|
|
234
|
+
* @param value - The amount of SOL to transfer (as a decimal string, e.g. "0.0001")
|
|
235
|
+
* @returns The signature
|
|
236
|
+
*/
|
|
237
|
+
async nativeTransfer(to, value) {
|
|
238
|
+
const initialBalance = await this.getBalance();
|
|
239
|
+
const solAmount = parseFloat(value);
|
|
240
|
+
const lamports = BigInt(Math.floor(solAmount * web3_js_1.LAMPORTS_PER_SOL));
|
|
241
|
+
// Check if we have enough balance (including estimated fees)
|
|
242
|
+
if (initialBalance < lamports + BigInt(5000)) {
|
|
243
|
+
throw new Error(`Insufficient balance. Have ${Number(initialBalance) / web3_js_1.LAMPORTS_PER_SOL} SOL, need ${solAmount + 0.000005} SOL (including fees)`);
|
|
244
|
+
}
|
|
245
|
+
const toPubkey = new web3_js_1.PublicKey(to);
|
|
246
|
+
const instructions = [
|
|
247
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
248
|
+
microLamports: 10000,
|
|
249
|
+
}),
|
|
250
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
251
|
+
units: 2000,
|
|
252
|
+
}),
|
|
253
|
+
web3_js_1.SystemProgram.transfer({
|
|
254
|
+
fromPubkey: __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey,
|
|
255
|
+
toPubkey: toPubkey,
|
|
256
|
+
lamports: lamports,
|
|
257
|
+
}),
|
|
258
|
+
];
|
|
259
|
+
const tx = new web3_js_1.VersionedTransaction(web3_js_1.MessageV0.compile({
|
|
260
|
+
payerKey: __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey,
|
|
261
|
+
instructions: instructions,
|
|
262
|
+
recentBlockhash: (await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getLatestBlockhash()).blockhash,
|
|
263
|
+
}));
|
|
264
|
+
tx.sign([__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f")]);
|
|
265
|
+
const signature = await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").sendTransaction(tx);
|
|
266
|
+
await this.waitForSignatureResult(signature);
|
|
267
|
+
return signature;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Request SOL tokens from the Solana faucet. This method only works on devnet and testnet networks.
|
|
271
|
+
*
|
|
272
|
+
* @param lamports - The amount of lamports (1 SOL = 1,000,000,000 lamports) to request from the faucet
|
|
273
|
+
* @returns A Promise that resolves to the signature of the airdrop
|
|
274
|
+
*/
|
|
275
|
+
async requestAirdrop(lamports) {
|
|
276
|
+
return await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").requestAirdrop(__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey, lamports);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.SolanaKeypairWalletProvider = SolanaKeypairWalletProvider;
|
|
280
|
+
_SolanaKeypairWalletProvider_keypair = new WeakMap(), _SolanaKeypairWalletProvider_connection = new WeakMap(), _SolanaKeypairWalletProvider_genesisHash = new WeakMap();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const solanaKeypairWalletProvider_1 = require("./solanaKeypairWalletProvider");
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const svm_1 = require("../network/svm");
|
|
6
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
7
|
+
ok: true,
|
|
8
|
+
json: () => Promise.resolve({}),
|
|
9
|
+
}));
|
|
10
|
+
jest.mock("../analytics", () => ({
|
|
11
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
12
|
+
}));
|
|
13
|
+
jest.mock("@solana/web3.js", () => {
|
|
14
|
+
const originalModule = jest.requireActual("@solana/web3.js");
|
|
15
|
+
return {
|
|
16
|
+
...originalModule,
|
|
17
|
+
Connection: jest.fn().mockImplementation(() => ({
|
|
18
|
+
getGenesisHash: jest.fn().mockResolvedValue(svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH),
|
|
19
|
+
getBalance: jest.fn().mockResolvedValue(1000000000),
|
|
20
|
+
getLatestBlockhash: jest.fn().mockResolvedValue({
|
|
21
|
+
blockhash: "test-blockhash",
|
|
22
|
+
lastValidBlockHeight: 123456,
|
|
23
|
+
}),
|
|
24
|
+
sendTransaction: jest.fn().mockResolvedValue("signature123"),
|
|
25
|
+
getSignatureStatus: jest.fn().mockResolvedValue({
|
|
26
|
+
context: { slot: 123 },
|
|
27
|
+
value: { slot: 123, confirmations: 10, err: null },
|
|
28
|
+
}),
|
|
29
|
+
confirmTransaction: jest.fn().mockResolvedValue({
|
|
30
|
+
context: { slot: 123 },
|
|
31
|
+
value: { err: null },
|
|
32
|
+
}),
|
|
33
|
+
requestAirdrop: jest.fn().mockResolvedValue("airdrop-signature"),
|
|
34
|
+
})),
|
|
35
|
+
Keypair: {
|
|
36
|
+
generate: jest.fn().mockReturnValue({
|
|
37
|
+
publicKey: new originalModule.PublicKey("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM"),
|
|
38
|
+
secretKey: new Uint8Array(32).fill(1),
|
|
39
|
+
sign: jest.fn(),
|
|
40
|
+
}),
|
|
41
|
+
fromSecretKey: jest.fn().mockReturnValue({
|
|
42
|
+
publicKey: new originalModule.PublicKey("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM"),
|
|
43
|
+
secretKey: new Uint8Array(32).fill(1),
|
|
44
|
+
sign: jest.fn(),
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
PublicKey: originalModule.PublicKey,
|
|
48
|
+
VersionedTransaction: jest.fn().mockImplementation(() => ({
|
|
49
|
+
signatures: [],
|
|
50
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
51
|
+
sign: jest.fn(function (signers) {
|
|
52
|
+
this.signatures = signers.map(() => new Uint8Array(64).fill(1));
|
|
53
|
+
return this;
|
|
54
|
+
}),
|
|
55
|
+
})),
|
|
56
|
+
SystemProgram: {
|
|
57
|
+
transfer: jest.fn().mockReturnValue({
|
|
58
|
+
instructions: [{ programId: "system-program" }],
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
MessageV0: {
|
|
62
|
+
compile: jest.fn().mockReturnValue({
|
|
63
|
+
compiledMessage: Buffer.from([]),
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
TransactionMessage: {
|
|
67
|
+
compile: jest.fn().mockReturnValue({
|
|
68
|
+
compiledMessage: Buffer.from([]),
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
clusterApiUrl: jest.fn().mockImplementation(network => `https://api.${network}.solana.com`),
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
describe("SolanaKeypairWalletProvider", () => {
|
|
75
|
+
let wallet;
|
|
76
|
+
beforeEach(async () => {
|
|
77
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
78
|
+
wallet = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromRpcUrl("https://api.devnet.solana.com", keypair.secretKey);
|
|
79
|
+
});
|
|
80
|
+
describe("initialization methods", () => {
|
|
81
|
+
it("should initialize from constructor", async () => {
|
|
82
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
83
|
+
const rpcUrl = "https://api.devnet.solana.com";
|
|
84
|
+
const provider = new solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider({
|
|
85
|
+
keypair: keypair.secretKey,
|
|
86
|
+
rpcUrl,
|
|
87
|
+
genesisHash: svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH,
|
|
88
|
+
});
|
|
89
|
+
expect(provider).toBeInstanceOf(solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider);
|
|
90
|
+
expect(provider.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH]);
|
|
91
|
+
});
|
|
92
|
+
it("should initialize from RPC URL", async () => {
|
|
93
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
94
|
+
const rpcUrl = "https://api.devnet.solana.com";
|
|
95
|
+
const provider = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromRpcUrl(rpcUrl, keypair.secretKey);
|
|
96
|
+
expect(provider).toBeInstanceOf(solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider);
|
|
97
|
+
expect(provider.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH]);
|
|
98
|
+
});
|
|
99
|
+
it("should initialize from network ID", async () => {
|
|
100
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
101
|
+
const networkId = "solana-devnet";
|
|
102
|
+
const wallet = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromNetwork(networkId, keypair.secretKey);
|
|
103
|
+
expect(web3_js_1.clusterApiUrl).toHaveBeenCalledWith("devnet");
|
|
104
|
+
expect(wallet.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH]);
|
|
105
|
+
});
|
|
106
|
+
it("should initialize from connection", async () => {
|
|
107
|
+
const keypair = web3_js_1.Keypair.generate();
|
|
108
|
+
const connection = new web3_js_1.Connection("https://api.devnet.solana.com");
|
|
109
|
+
const provider = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromConnection(connection, keypair.secretKey);
|
|
110
|
+
expect(provider).toBeInstanceOf(solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider);
|
|
111
|
+
expect(provider.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH]);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe("wallet methods", () => {
|
|
115
|
+
it("should get the address", () => {
|
|
116
|
+
expect(wallet.getAddress()).toBe("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM");
|
|
117
|
+
});
|
|
118
|
+
it("should get the public key", () => {
|
|
119
|
+
const publicKey = wallet.getPublicKey();
|
|
120
|
+
expect(publicKey).toBeInstanceOf(web3_js_1.PublicKey);
|
|
121
|
+
expect(publicKey.toBase58()).toBe("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM");
|
|
122
|
+
});
|
|
123
|
+
it("should get the network", () => {
|
|
124
|
+
expect(wallet.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH]);
|
|
125
|
+
});
|
|
126
|
+
it("should get the connection", () => {
|
|
127
|
+
expect(wallet.getConnection()).toBeDefined();
|
|
128
|
+
});
|
|
129
|
+
it("should get the balance", async () => {
|
|
130
|
+
const balance = await wallet.getBalance();
|
|
131
|
+
expect(balance).toBe(BigInt(1000000000));
|
|
132
|
+
});
|
|
133
|
+
it("should sign a transaction", async () => {
|
|
134
|
+
const mockTransaction = {
|
|
135
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
136
|
+
signatures: [],
|
|
137
|
+
sign: jest.fn(function (signers) {
|
|
138
|
+
this.signatures = signers.map(() => new Uint8Array(64).fill(1));
|
|
139
|
+
return this;
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
const signedTx = await wallet.signTransaction(mockTransaction);
|
|
143
|
+
expect(mockTransaction.sign).toHaveBeenCalled();
|
|
144
|
+
expect(signedTx).toBe(mockTransaction);
|
|
145
|
+
});
|
|
146
|
+
it("should send a transaction", async () => {
|
|
147
|
+
const mockTransaction = {
|
|
148
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
149
|
+
signatures: [],
|
|
150
|
+
sign: jest.fn(function (signers) {
|
|
151
|
+
this.signatures = signers.map(() => new Uint8Array(64).fill(1));
|
|
152
|
+
return this;
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
const signature = await wallet.sendTransaction(mockTransaction);
|
|
156
|
+
expect(signature).toBe("signature123");
|
|
157
|
+
});
|
|
158
|
+
it("should sign and send a transaction", async () => {
|
|
159
|
+
const mockTransaction = {
|
|
160
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
161
|
+
signatures: [],
|
|
162
|
+
sign: jest.fn(function (signers) {
|
|
163
|
+
this.signatures = signers.map(() => new Uint8Array(64).fill(1));
|
|
164
|
+
return this;
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
const signature = await wallet.signAndSendTransaction(mockTransaction);
|
|
168
|
+
expect(mockTransaction.sign).toHaveBeenCalled();
|
|
169
|
+
expect(signature).toBe("signature123");
|
|
170
|
+
});
|
|
171
|
+
it("should get the signature status", async () => {
|
|
172
|
+
const status = await wallet.getSignatureStatus("signature123");
|
|
173
|
+
expect(status.value).toHaveProperty("slot");
|
|
174
|
+
expect(status.value).toHaveProperty("confirmations");
|
|
175
|
+
});
|
|
176
|
+
it("should wait for signature result", async () => {
|
|
177
|
+
const result = await wallet.waitForSignatureResult("signature123");
|
|
178
|
+
expect(result.value).toHaveProperty("err");
|
|
179
|
+
});
|
|
180
|
+
it("should request an airdrop", async () => {
|
|
181
|
+
const signature = await wallet.requestAirdrop(1000000000);
|
|
182
|
+
expect(signature).toBe("airdrop-signature");
|
|
183
|
+
});
|
|
184
|
+
it("should transfer native tokens", async () => {
|
|
185
|
+
const destination = "EQJqzeeVEnm8rKWQJ5SMTtQBD4xEgixwgzNWKkpeFRZ9";
|
|
186
|
+
const signature = await wallet.nativeTransfer(destination, "0.1");
|
|
187
|
+
expect(signature).toBe("signature123");
|
|
188
|
+
});
|
|
189
|
+
it("should handle insufficient balance when transferring", async () => {
|
|
190
|
+
const connection = wallet.getConnection();
|
|
191
|
+
connection.getBalance.mockResolvedValueOnce(100);
|
|
192
|
+
const destination = "EQJqzeeVEnm8rKWQJ5SMTtQBD4xEgixwgzNWKkpeFRZ9";
|
|
193
|
+
await expect(wallet.nativeTransfer(destination, "1.0")).rejects.toThrow("Insufficient balance");
|
|
194
|
+
});
|
|
195
|
+
it("should handle transaction failure when sending", async () => {
|
|
196
|
+
const connection = wallet.getConnection();
|
|
197
|
+
connection.sendTransaction.mockRejectedValueOnce(new Error("Transaction failed"));
|
|
198
|
+
const mockTransaction = {
|
|
199
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
200
|
+
signatures: [],
|
|
201
|
+
sign: jest.fn(function (signers) {
|
|
202
|
+
this.signatures = signers.map(() => new Uint8Array(64).fill(1));
|
|
203
|
+
return this;
|
|
204
|
+
}),
|
|
205
|
+
};
|
|
206
|
+
await expect(wallet.sendTransaction(mockTransaction)).rejects.toThrow("Transaction failed");
|
|
207
|
+
});
|
|
208
|
+
it("should handle confirmation timeout", async () => {
|
|
209
|
+
const connection = wallet.getConnection();
|
|
210
|
+
connection.confirmTransaction.mockRejectedValueOnce(new Error("Timed out waiting for confirmation"));
|
|
211
|
+
await expect(wallet.waitForSignatureResult("signature123")).rejects.toThrow("Timed out waiting for confirmation");
|
|
212
|
+
});
|
|
213
|
+
it("should handle invalid address when transferring", async () => {
|
|
214
|
+
const destination = "invalid-address";
|
|
215
|
+
await expect(wallet.nativeTransfer(destination, "0.1")).rejects.toThrow();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { WalletProvider } from "./walletProvider";
|
|
2
|
+
import { Connection, PublicKey, RpcResponseAndContext, SignatureStatus, SignatureStatusConfig, VersionedTransaction, SignatureResult } from "@solana/web3.js";
|
|
3
|
+
/**
|
|
4
|
+
* SvmWalletProvider is the abstract base class for all Solana wallet providers (non browsers).
|
|
5
|
+
*
|
|
6
|
+
* @abstract
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class SvmWalletProvider extends WalletProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Get the connection instance.
|
|
11
|
+
*
|
|
12
|
+
* @returns The Solana connection instance.
|
|
13
|
+
*/
|
|
14
|
+
abstract getConnection(): Connection;
|
|
15
|
+
/**
|
|
16
|
+
* Get the public key of the wallet.
|
|
17
|
+
*
|
|
18
|
+
* @returns The wallet's public key.
|
|
19
|
+
*/
|
|
20
|
+
abstract getPublicKey(): PublicKey;
|
|
21
|
+
/**
|
|
22
|
+
* Sign a transaction.
|
|
23
|
+
*
|
|
24
|
+
* @param transaction - The transaction to sign.
|
|
25
|
+
* @returns The signed transaction.
|
|
26
|
+
*/
|
|
27
|
+
abstract signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
28
|
+
/**
|
|
29
|
+
* Send a transaction.
|
|
30
|
+
*
|
|
31
|
+
* @param transaction - The transaction to send.
|
|
32
|
+
* @returns The signature.
|
|
33
|
+
*/
|
|
34
|
+
abstract sendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Sign and send a transaction.
|
|
37
|
+
*
|
|
38
|
+
* @param transaction - The transaction to sign and send.
|
|
39
|
+
* @returns The signature.
|
|
40
|
+
*/
|
|
41
|
+
abstract signAndSendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the status of a transaction.
|
|
44
|
+
*
|
|
45
|
+
* @param signature - The signature.
|
|
46
|
+
* @returns The status.
|
|
47
|
+
*/
|
|
48
|
+
abstract getSignatureStatus(signature: string, options?: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus | null>>;
|
|
49
|
+
/**
|
|
50
|
+
* Wait for signature receipt.
|
|
51
|
+
*
|
|
52
|
+
* @param signature - The signature
|
|
53
|
+
* @returns The confirmation response
|
|
54
|
+
*/
|
|
55
|
+
abstract waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SvmWalletProvider = void 0;
|
|
5
|
+
const walletProvider_1 = require("./walletProvider");
|
|
6
|
+
/**
|
|
7
|
+
* SvmWalletProvider is the abstract base class for all Solana wallet providers (non browsers).
|
|
8
|
+
*
|
|
9
|
+
* @abstract
|
|
10
|
+
*/
|
|
11
|
+
class SvmWalletProvider extends walletProvider_1.WalletProvider {
|
|
12
|
+
}
|
|
13
|
+
exports.SvmWalletProvider = SvmWalletProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const svmWalletProvider_1 = require("./svmWalletProvider");
|
|
4
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
5
|
+
ok: true,
|
|
6
|
+
json: () => Promise.resolve({}),
|
|
7
|
+
}));
|
|
8
|
+
jest.mock("../analytics", () => ({
|
|
9
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
10
|
+
}));
|
|
11
|
+
describe("SvmWalletProvider", () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.getConnection) {
|
|
15
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.getConnection = jest.fn();
|
|
16
|
+
}
|
|
17
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.getPublicKey) {
|
|
18
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.getPublicKey = jest.fn();
|
|
19
|
+
}
|
|
20
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.signTransaction) {
|
|
21
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.signTransaction = jest.fn();
|
|
22
|
+
}
|
|
23
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.sendTransaction) {
|
|
24
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.sendTransaction = jest.fn();
|
|
25
|
+
}
|
|
26
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.signAndSendTransaction) {
|
|
27
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.signAndSendTransaction = jest.fn();
|
|
28
|
+
}
|
|
29
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.getSignatureStatus) {
|
|
30
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.getSignatureStatus = jest.fn();
|
|
31
|
+
}
|
|
32
|
+
if (!svmWalletProvider_1.SvmWalletProvider.prototype.waitForSignatureResult) {
|
|
33
|
+
svmWalletProvider_1.SvmWalletProvider.prototype.waitForSignatureResult = jest.fn();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
it("should extend WalletProvider", () => {
|
|
37
|
+
const proto = Object.getPrototypeOf(svmWalletProvider_1.SvmWalletProvider);
|
|
38
|
+
const protoName = proto.name;
|
|
39
|
+
expect(protoName).toBe("WalletProvider");
|
|
40
|
+
});
|
|
41
|
+
it("should have consistent method signatures", () => {
|
|
42
|
+
const signTransactionDescriptor = Object.getOwnPropertyDescriptor(svmWalletProvider_1.SvmWalletProvider.prototype, "signTransaction");
|
|
43
|
+
expect(signTransactionDescriptor).toBeDefined();
|
|
44
|
+
expect(typeof signTransactionDescriptor.value).toBe("function");
|
|
45
|
+
const sendTransactionDescriptor = Object.getOwnPropertyDescriptor(svmWalletProvider_1.SvmWalletProvider.prototype, "sendTransaction");
|
|
46
|
+
expect(sendTransactionDescriptor).toBeDefined();
|
|
47
|
+
expect(typeof sendTransactionDescriptor.value).toBe("function");
|
|
48
|
+
const getPublicKeyDescriptor = Object.getOwnPropertyDescriptor(svmWalletProvider_1.SvmWalletProvider.prototype, "getPublicKey");
|
|
49
|
+
expect(getPublicKeyDescriptor).toBeDefined();
|
|
50
|
+
expect(typeof getPublicKeyDescriptor.value).toBe("function");
|
|
51
|
+
const getConnectionDescriptor = Object.getOwnPropertyDescriptor(svmWalletProvider_1.SvmWalletProvider.prototype, "getConnection");
|
|
52
|
+
expect(getConnectionDescriptor).toBeDefined();
|
|
53
|
+
expect(typeof getConnectionDescriptor.value).toBe("function");
|
|
54
|
+
});
|
|
55
|
+
});
|