@coinbase/agentkit 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/action-providers/across/acrossActionProvider.js +3 -3
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +223 -23
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +278 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +223 -18
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +265 -1
- package/dist/action-providers/cdp/schemas.d.ts +12 -12
- package/dist/action-providers/cdp/schemas.js +17 -5
- package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
- package/dist/action-providers/cdp/swapUtils.js +142 -0
- package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
- package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
- package/dist/action-providers/clanker/index.d.ts +2 -0
- package/dist/action-providers/clanker/index.js +18 -0
- package/dist/action-providers/clanker/schemas.d.ts +56 -0
- package/dist/action-providers/clanker/schemas.js +47 -0
- package/dist/action-providers/clanker/utils.d.ts +9 -0
- package/dist/action-providers/clanker/utils.js +23 -0
- package/dist/action-providers/compound/constants.d.ts +1 -1
- package/dist/action-providers/compound/constants.js +2 -2
- package/dist/action-providers/erc20/constants.d.ts +35 -135
- package/dist/action-providers/erc20/constants.js +37 -189
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
- package/dist/action-providers/erc20/schemas.d.ts +25 -12
- package/dist/action-providers/erc20/schemas.js +34 -6
- package/dist/action-providers/erc20/utils.d.ts +19 -0
- package/dist/action-providers/erc20/utils.js +54 -0
- package/dist/action-providers/flaunch/constants.d.ts +1 -1
- package/dist/action-providers/flaunch/constants.js +2 -2
- package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
- package/dist/action-providers/index.d.ts +3 -0
- package/dist/action-providers/index.js +3 -0
- package/dist/action-providers/jupiter/schemas.d.ts +1 -1
- package/dist/action-providers/moonwell/schemas.d.ts +2 -2
- package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
- package/dist/action-providers/morpho/schemas.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +5 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +5 -1
- package/dist/action-providers/superfluid/constants.d.ts +814 -0
- package/dist/action-providers/superfluid/constants.js +2826 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
- package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
- package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
- package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
- package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
- package/dist/action-providers/superfluid/index.d.ts +7 -0
- package/dist/action-providers/superfluid/index.js +23 -0
- package/dist/action-providers/superfluid/schemas.d.ts +86 -0
- package/dist/action-providers/superfluid/schemas.js +103 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
- package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
- package/dist/action-providers/wallet/walletActionProvider.js +21 -10
- package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
- package/dist/action-providers/zeroX/index.d.ts +1 -0
- package/dist/action-providers/zeroX/index.js +17 -0
- package/dist/action-providers/zeroX/schemas.d.ts +51 -0
- package/dist/action-providers/zeroX/schemas.js +82 -0
- package/dist/action-providers/zeroX/utils.d.ts +23 -0
- package/dist/action-providers/zeroX/utils.js +106 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +20 -2
- package/dist/wallet-providers/cdpEvmWalletProvider.js +40 -15
- package/dist/wallet-providers/cdpShared.d.ts +5 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +22 -3
- package/dist/wallet-providers/cdpSmartWalletProvider.js +43 -19
- package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
- package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +12 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +12 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.js +11 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +10 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +12 -3
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
- package/dist/wallet-providers/viemWalletProvider.d.ts +12 -2
- package/dist/wallet-providers/viemWalletProvider.js +12 -3
- package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +10 -2
- package/dist/wallet-providers/zeroDevWalletProvider.js +14 -5
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
- package/package.json +4 -2
|
@@ -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
|
|
13
|
+
var _CdpSmartWalletProvider_publicClient, _CdpSmartWalletProvider_cdp, _CdpSmartWalletProvider_network, _CdpSmartWalletProvider_paymasterUrl;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CdpSmartWalletProvider = void 0;
|
|
16
16
|
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
@@ -28,14 +28,12 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
28
28
|
*/
|
|
29
29
|
constructor(config) {
|
|
30
30
|
super();
|
|
31
|
-
_CdpSmartWalletProvider_instances.add(this);
|
|
32
31
|
_CdpSmartWalletProvider_publicClient.set(this, void 0);
|
|
33
|
-
_CdpSmartWalletProvider_ownerAccount.set(this, void 0);
|
|
34
32
|
_CdpSmartWalletProvider_cdp.set(this, void 0);
|
|
35
33
|
_CdpSmartWalletProvider_network.set(this, void 0);
|
|
36
34
|
_CdpSmartWalletProvider_paymasterUrl.set(this, void 0);
|
|
37
35
|
this.smartAccount = config.smartAccount;
|
|
38
|
-
|
|
36
|
+
this.ownerAccount = config.ownerAccount;
|
|
39
37
|
__classPrivateFieldSet(this, _CdpSmartWalletProvider_cdp, config.cdp, "f");
|
|
40
38
|
__classPrivateFieldSet(this, _CdpSmartWalletProvider_publicClient, config.publicClient, "f");
|
|
41
39
|
__classPrivateFieldSet(this, _CdpSmartWalletProvider_network, config.network, "f");
|
|
@@ -92,9 +90,10 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
92
90
|
: cdpClient.evm.createSmartAccount({
|
|
93
91
|
owner: ownerAccount,
|
|
94
92
|
}));
|
|
93
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
95
94
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
96
95
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
|
|
97
|
-
transport: (0, viem_1.http)(),
|
|
96
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
98
97
|
});
|
|
99
98
|
return new CdpSmartWalletProvider({
|
|
100
99
|
publicClient,
|
|
@@ -114,7 +113,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
114
113
|
return {
|
|
115
114
|
name: this.smartAccount.name,
|
|
116
115
|
address: this.smartAccount.address,
|
|
117
|
-
ownerAddress:
|
|
116
|
+
ownerAddress: this.ownerAccount.address,
|
|
118
117
|
};
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
@@ -140,7 +139,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
140
139
|
types,
|
|
141
140
|
primaryType,
|
|
142
141
|
message,
|
|
143
|
-
network:
|
|
142
|
+
network: this.getCdpSdkNetwork(),
|
|
144
143
|
});
|
|
145
144
|
}
|
|
146
145
|
/**
|
|
@@ -168,7 +167,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
168
167
|
];
|
|
169
168
|
const userOperation = await __classPrivateFieldGet(this, _CdpSmartWalletProvider_cdp, "f").evm.sendUserOperation({
|
|
170
169
|
smartAccount: this.smartAccount,
|
|
171
|
-
network:
|
|
170
|
+
network: this.getCdpSdkNetwork(),
|
|
172
171
|
calls,
|
|
173
172
|
paymasterUrl: __classPrivateFieldGet(this, _CdpSmartWalletProvider_paymasterUrl, "f"),
|
|
174
173
|
});
|
|
@@ -214,6 +213,14 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
214
213
|
getPaymasterUrl() {
|
|
215
214
|
return __classPrivateFieldGet(this, _CdpSmartWalletProvider_paymasterUrl, "f");
|
|
216
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
218
|
+
*
|
|
219
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
220
|
+
*/
|
|
221
|
+
getPublicClient() {
|
|
222
|
+
return __classPrivateFieldGet(this, _CdpSmartWalletProvider_publicClient, "f");
|
|
223
|
+
}
|
|
217
224
|
/**
|
|
218
225
|
* Gets the balance of the smart wallet.
|
|
219
226
|
*
|
|
@@ -251,7 +258,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
251
258
|
* Transfer the native asset of the network using smart wallet.
|
|
252
259
|
*
|
|
253
260
|
* @param to - The destination address.
|
|
254
|
-
* @param value - The amount to transfer in Wei.
|
|
261
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
255
262
|
* @returns The user operation hash.
|
|
256
263
|
*/
|
|
257
264
|
async nativeTransfer(to, value) {
|
|
@@ -261,15 +268,32 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
261
268
|
data: "0x",
|
|
262
269
|
});
|
|
263
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Converts the internal network ID to the format expected by the CDP SDK.
|
|
273
|
+
*
|
|
274
|
+
* @returns The network ID in CDP SDK format
|
|
275
|
+
* @throws Error if the network is not supported
|
|
276
|
+
*/
|
|
277
|
+
getCdpSdkNetwork() {
|
|
278
|
+
switch (__classPrivateFieldGet(this, _CdpSmartWalletProvider_network, "f").networkId) {
|
|
279
|
+
case "base-sepolia":
|
|
280
|
+
return "base-sepolia";
|
|
281
|
+
case "base-mainnet":
|
|
282
|
+
return "base";
|
|
283
|
+
case "ethereum-mainnet":
|
|
284
|
+
return "ethereum";
|
|
285
|
+
case "ethereum-sepolia":
|
|
286
|
+
return "ethereum-sepolia";
|
|
287
|
+
case "polygon-mainnet":
|
|
288
|
+
return "polygon";
|
|
289
|
+
case "arbitrum-mainnet":
|
|
290
|
+
return "arbitrum";
|
|
291
|
+
case "optimism-mainnet":
|
|
292
|
+
return "optimism";
|
|
293
|
+
default:
|
|
294
|
+
throw new Error(`Unsupported network for smart wallets: ${__classPrivateFieldGet(this, _CdpSmartWalletProvider_network, "f").networkId}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
264
297
|
}
|
|
265
298
|
exports.CdpSmartWalletProvider = CdpSmartWalletProvider;
|
|
266
|
-
_CdpSmartWalletProvider_publicClient = new WeakMap(),
|
|
267
|
-
switch (__classPrivateFieldGet(this, _CdpSmartWalletProvider_network, "f").networkId) {
|
|
268
|
-
case "base-sepolia":
|
|
269
|
-
return "base-sepolia";
|
|
270
|
-
case "base-mainnet":
|
|
271
|
-
return "base";
|
|
272
|
-
default:
|
|
273
|
-
throw new Error(`Unsupported network for smart wallets: ${__classPrivateFieldGet(this, _CdpSmartWalletProvider_network, "f").networkId}`);
|
|
274
|
-
}
|
|
275
|
-
};
|
|
299
|
+
_CdpSmartWalletProvider_publicClient = new WeakMap(), _CdpSmartWalletProvider_cdp = new WeakMap(), _CdpSmartWalletProvider_network = new WeakMap(), _CdpSmartWalletProvider_paymasterUrl = new WeakMap();
|
|
@@ -113,7 +113,7 @@ export declare class CdpSolanaWalletProvider extends SvmWalletProvider implement
|
|
|
113
113
|
* Transfer SOL from the wallet to another address
|
|
114
114
|
*
|
|
115
115
|
* @param to - The base58 encoded address to transfer the SOL to
|
|
116
|
-
* @param value - The amount
|
|
116
|
+
* @param value - The amount to transfer in atomic units (Lamports)
|
|
117
117
|
* @returns The signature
|
|
118
118
|
*/
|
|
119
119
|
nativeTransfer(to: string, value: string): Promise<string>;
|
|
@@ -147,12 +147,13 @@ class CdpSolanaWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
147
147
|
async signTransaction(transaction) {
|
|
148
148
|
const serializedTransaction = transaction.serialize();
|
|
149
149
|
const encodedSerializedTransaction = Buffer.from(serializedTransaction).toString("base64");
|
|
150
|
-
const
|
|
150
|
+
const signedTransactionResponse = await __classPrivateFieldGet(this, _CdpSolanaWalletProvider_cdp, "f").solana.signTransaction({
|
|
151
151
|
transaction: encodedSerializedTransaction,
|
|
152
152
|
address: __classPrivateFieldGet(this, _CdpSolanaWalletProvider_serverAccount, "f").address,
|
|
153
153
|
});
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
const signedTransactionBytes = Buffer.from(signedTransactionResponse.signedTransaction, "base64");
|
|
155
|
+
const signedTransaction = web3_js_1.VersionedTransaction.deserialize(signedTransactionBytes);
|
|
156
|
+
return signedTransaction;
|
|
156
157
|
}
|
|
157
158
|
/**
|
|
158
159
|
* Send a transaction
|
|
@@ -219,16 +220,15 @@ class CdpSolanaWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
219
220
|
* Transfer SOL from the wallet to another address
|
|
220
221
|
*
|
|
221
222
|
* @param to - The base58 encoded address to transfer the SOL to
|
|
222
|
-
* @param value - The amount
|
|
223
|
+
* @param value - The amount to transfer in atomic units (Lamports)
|
|
223
224
|
* @returns The signature
|
|
224
225
|
*/
|
|
225
226
|
async nativeTransfer(to, value) {
|
|
226
227
|
const initialBalance = await this.getBalance();
|
|
227
|
-
const
|
|
228
|
-
const lamports = BigInt(Math.floor(solAmount * web3_js_1.LAMPORTS_PER_SOL));
|
|
228
|
+
const lamports = BigInt(value);
|
|
229
229
|
// Check if we have enough balance (including estimated fees)
|
|
230
230
|
if (initialBalance < lamports + BigInt(5000)) {
|
|
231
|
-
throw new Error(`Insufficient balance. Have ${Number(initialBalance)
|
|
231
|
+
throw new Error(`Insufficient balance. Have ${Number(initialBalance)} lamports, need ${Number(lamports) + 5000} lamports (including fees)`);
|
|
232
232
|
}
|
|
233
233
|
const toPubkey = new web3_js_1.PublicKey(to);
|
|
234
234
|
const instructions = [
|
|
@@ -29,13 +29,16 @@ jest.mock("@solana/web3.js", () => {
|
|
|
29
29
|
};
|
|
30
30
|
const MockPublicKey = jest.fn(() => mockPublicKey);
|
|
31
31
|
MockPublicKey.prototype = mockPublicKey;
|
|
32
|
+
const mockVersionedTransaction = {
|
|
33
|
+
serialize: jest.fn(() => Buffer.from("mock-serialized-tx")),
|
|
34
|
+
addSignature: jest.fn(),
|
|
35
|
+
};
|
|
36
|
+
const MockVersionedTransaction = jest.fn(() => mockVersionedTransaction);
|
|
37
|
+
MockVersionedTransaction.deserialize = jest.fn(() => mockVersionedTransaction);
|
|
32
38
|
return {
|
|
33
39
|
Connection: jest.fn(() => mockConnection),
|
|
34
40
|
PublicKey: MockPublicKey,
|
|
35
|
-
VersionedTransaction:
|
|
36
|
-
serialize: jest.fn(() => Buffer.from("mock-serialized-tx")),
|
|
37
|
-
addSignature: jest.fn(),
|
|
38
|
-
})),
|
|
41
|
+
VersionedTransaction: MockVersionedTransaction,
|
|
39
42
|
MessageV0: {
|
|
40
43
|
compile: jest.fn(),
|
|
41
44
|
},
|
|
@@ -69,9 +72,9 @@ jest.mock("@coinbase/cdp-sdk", () => {
|
|
|
69
72
|
address: MOCK_ADDRESS,
|
|
70
73
|
signTransaction: jest.fn().mockResolvedValue({ signature: MOCK_SIGNATURE }),
|
|
71
74
|
}));
|
|
72
|
-
const mockSignTransaction = jest
|
|
73
|
-
.
|
|
74
|
-
|
|
75
|
+
const mockSignTransaction = jest.fn().mockImplementation(async () => ({
|
|
76
|
+
signedTransaction: Buffer.from("mock-signed-transaction").toString("base64"),
|
|
77
|
+
}));
|
|
75
78
|
const mockSolanaClient = {
|
|
76
79
|
createAccount: mockCreateAccount,
|
|
77
80
|
getAccount: jest.fn(),
|
|
@@ -122,9 +125,9 @@ describe("CdpSolanaWalletProvider", () => {
|
|
|
122
125
|
};
|
|
123
126
|
// Set up the mock server account for the provider
|
|
124
127
|
mockCdpClient.solana.createAccount.mockResolvedValue(mockServerAccount);
|
|
125
|
-
mockCdpClient.solana.signTransaction = jest
|
|
126
|
-
.
|
|
127
|
-
|
|
128
|
+
mockCdpClient.solana.signTransaction = jest.fn().mockResolvedValue({
|
|
129
|
+
signedTransaction: Buffer.from("mock-signed-transaction").toString("base64"),
|
|
130
|
+
});
|
|
128
131
|
mockConnection.getBalance.mockResolvedValue(Number(MOCK_BALANCE));
|
|
129
132
|
mockConnection.getLatestBlockhash.mockResolvedValue({
|
|
130
133
|
blockhash: "test-blockhash",
|
|
@@ -285,7 +288,7 @@ describe("CdpSolanaWalletProvider", () => {
|
|
|
285
288
|
describe("native transfer", () => {
|
|
286
289
|
it("should transfer SOL", async () => {
|
|
287
290
|
const toAddress = "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin";
|
|
288
|
-
const amount = "
|
|
291
|
+
const amount = "1000000000"; // 1 SOL in lamports
|
|
289
292
|
// Set a balance that's high enough to cover the transfer + fees
|
|
290
293
|
mockConnection.getBalance.mockResolvedValueOnce(Number(2000000000n)); // 2 SOL
|
|
291
294
|
const signature = await provider.nativeTransfer(toAddress, amount);
|
|
@@ -295,7 +298,7 @@ describe("CdpSolanaWalletProvider", () => {
|
|
|
295
298
|
it("should handle insufficient balance", async () => {
|
|
296
299
|
mockConnection.getBalance.mockResolvedValueOnce(Number(1000000n)); // 0.001 SOL
|
|
297
300
|
const toAddress = "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin";
|
|
298
|
-
const amount = "
|
|
301
|
+
const amount = "1000000000"; // 1 SOL in lamports
|
|
299
302
|
await expect(provider.nativeTransfer(toAddress, amount)).rejects.toThrow("Insufficient balance");
|
|
300
303
|
});
|
|
301
304
|
it("should handle invalid address", async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WalletProvider } from "./walletProvider";
|
|
2
|
-
import { TransactionRequest, ReadContractParameters, ReadContractReturnType, ContractFunctionName, Abi, ContractFunctionArgs, Account } from "viem";
|
|
2
|
+
import { TransactionRequest, ReadContractParameters, ReadContractReturnType, ContractFunctionName, Abi, ContractFunctionArgs, Account, PublicClient } from "viem";
|
|
3
3
|
/**
|
|
4
4
|
* EvmWalletProvider is the abstract base class for all EVM wallet providers.
|
|
5
5
|
*
|
|
@@ -54,4 +54,8 @@ export declare abstract class EvmWalletProvider extends WalletProvider {
|
|
|
54
54
|
* @returns The response from the contract.
|
|
55
55
|
*/
|
|
56
56
|
abstract readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>;
|
|
57
|
+
/**
|
|
58
|
+
* Get the underlying Viem PublicClient for read-only blockchain operations.
|
|
59
|
+
*/
|
|
60
|
+
abstract getPublicClient(): PublicClient;
|
|
57
61
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SendUserOperationOptions, Signer } from "@coinbase/coinbase-sdk";
|
|
2
|
-
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
2
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest, PublicClient as ViemPublicClient } from "viem";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
5
|
export interface ConfigureLegacyCdpSmartWalletOptions {
|
|
@@ -9,6 +9,7 @@ export interface ConfigureLegacyCdpSmartWalletOptions {
|
|
|
9
9
|
smartWalletAddress?: Hex;
|
|
10
10
|
paymasterUrl?: string;
|
|
11
11
|
signer: Signer;
|
|
12
|
+
rpcUrl?: string;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* A wallet provider that uses Smart Wallets from the Coinbase SDK.
|
|
@@ -146,6 +147,12 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
|
|
|
146
147
|
* @returns The name of the wallet provider.
|
|
147
148
|
*/
|
|
148
149
|
getName(): string;
|
|
150
|
+
/**
|
|
151
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
152
|
+
*
|
|
153
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
154
|
+
*/
|
|
155
|
+
getPublicClient(): ViemPublicClient;
|
|
149
156
|
/**
|
|
150
157
|
* Gets the balance of the wallet.
|
|
151
158
|
*
|
|
@@ -170,7 +177,7 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
|
|
|
170
177
|
* Transfer the native asset of the network.
|
|
171
178
|
*
|
|
172
179
|
* @param to - The destination address.
|
|
173
|
-
* @param value - The amount to transfer in Wei.
|
|
180
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
174
181
|
* @returns The transaction hash.
|
|
175
182
|
*/
|
|
176
183
|
nativeTransfer(to: Address, value: string): Promise<Hex>;
|
|
@@ -34,9 +34,10 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
34
34
|
_LegacyCdpSmartWalletProvider_publicClient.set(this, void 0);
|
|
35
35
|
__classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_network, config.network, "f");
|
|
36
36
|
__classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_smartWallet, config.smartWallet, "f");
|
|
37
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
37
38
|
__classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
38
39
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
39
|
-
transport: (0, viem_1.http)(),
|
|
40
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
40
41
|
}), "f");
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
@@ -106,6 +107,7 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
106
107
|
smartWallet: networkScopedSmartWallet,
|
|
107
108
|
network,
|
|
108
109
|
chainId: network.chainId,
|
|
110
|
+
rpcUrl: config.rpcUrl,
|
|
109
111
|
});
|
|
110
112
|
return legacyCdpSmartWalletProvider;
|
|
111
113
|
}
|
|
@@ -242,6 +244,14 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
242
244
|
getName() {
|
|
243
245
|
return "legacy_cdp_smart_wallet_provider";
|
|
244
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
249
|
+
*
|
|
250
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
251
|
+
*/
|
|
252
|
+
getPublicClient() {
|
|
253
|
+
return __classPrivateFieldGet(this, _LegacyCdpSmartWalletProvider_publicClient, "f");
|
|
254
|
+
}
|
|
245
255
|
/**
|
|
246
256
|
* Gets the balance of the wallet.
|
|
247
257
|
*
|
|
@@ -278,7 +288,7 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
278
288
|
* Transfer the native asset of the network.
|
|
279
289
|
*
|
|
280
290
|
* @param to - The destination address.
|
|
281
|
-
* @param value - The amount to transfer in Wei.
|
|
291
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
282
292
|
* @returns The transaction hash.
|
|
283
293
|
*/
|
|
284
294
|
async nativeTransfer(to, value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, Abi, ContractFunctionName, ContractFunctionArgs, Address, Hex } from "viem";
|
|
1
|
+
import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, PublicClient, Abi, ContractFunctionName, ContractFunctionArgs, Address, Hex } from "viem";
|
|
2
2
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { Coinbase, CreateERC20Options, CreateTradeOptions, SmartContract, Trade, Wallet, WalletData } from "@coinbase/coinbase-sdk";
|
|
@@ -50,6 +50,10 @@ export interface LegacyCdpWalletProviderConfig extends LegacyCdpProviderConfig {
|
|
|
50
50
|
*/
|
|
51
51
|
feePerGasMultiplier?: number;
|
|
52
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Optional RPC URL for Viem public client.
|
|
55
|
+
*/
|
|
56
|
+
rpcUrl?: string;
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
55
59
|
* Configuration options for the CDP Agentkit with a Wallet.
|
|
@@ -148,6 +152,12 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
|
|
|
148
152
|
* @returns The name of the wallet provider.
|
|
149
153
|
*/
|
|
150
154
|
getName(): string;
|
|
155
|
+
/**
|
|
156
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
157
|
+
*
|
|
158
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
159
|
+
*/
|
|
160
|
+
getPublicClient(): PublicClient;
|
|
151
161
|
/**
|
|
152
162
|
* Gets the balance of the wallet.
|
|
153
163
|
*
|
|
@@ -221,7 +231,7 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
|
|
|
221
231
|
* Transfer the native asset of the network.
|
|
222
232
|
*
|
|
223
233
|
* @param to - The destination address.
|
|
224
|
-
* @param value - The amount to transfer in Wei.
|
|
234
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
225
235
|
* @returns The transaction hash.
|
|
226
236
|
*/
|
|
227
237
|
nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
|
|
@@ -43,9 +43,10 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
43
43
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_cdpWallet, config.wallet, "f");
|
|
44
44
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_address, config.address, "f");
|
|
45
45
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_network, config.network, "f");
|
|
46
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
46
47
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
47
48
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
48
|
-
transport: (0, viem_1.http)(),
|
|
49
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
49
50
|
}), "f");
|
|
50
51
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_gasLimitMultiplier, Math.max(config.gas?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
51
52
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_feePerGasMultiplier, Math.max(config.gas?.feePerGasMultiplier ?? 1, 1), "f");
|
|
@@ -268,6 +269,14 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
268
269
|
getName() {
|
|
269
270
|
return "legacy_cdp_wallet_provider";
|
|
270
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
274
|
+
*
|
|
275
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
276
|
+
*/
|
|
277
|
+
getPublicClient() {
|
|
278
|
+
return __classPrivateFieldGet(this, _LegacyCdpWalletProvider_publicClient, "f");
|
|
279
|
+
}
|
|
271
280
|
/**
|
|
272
281
|
* Gets the balance of the wallet.
|
|
273
282
|
*
|
|
@@ -363,7 +372,7 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
363
372
|
* Transfer the native asset of the network.
|
|
364
373
|
*
|
|
365
374
|
* @param to - The destination address.
|
|
366
|
-
* @param value - The amount to transfer in Wei.
|
|
375
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
367
376
|
* @returns The transaction hash.
|
|
368
377
|
*/
|
|
369
378
|
async nativeTransfer(to, value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionReceipt, TransactionRequest } from "viem";
|
|
1
|
+
import { Abi, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionReceipt, TransactionRequest } from "viem";
|
|
2
2
|
import { Network } from "../network";
|
|
3
3
|
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
4
4
|
import { WalletProvider } from "./walletProvider";
|
|
@@ -14,6 +14,8 @@ export interface PrivyEvmDelegatedEmbeddedWalletConfig extends PrivyWalletConfig
|
|
|
14
14
|
chainId?: string;
|
|
15
15
|
/** The wallet type to use */
|
|
16
16
|
walletType: "embedded";
|
|
17
|
+
/** Optional RPC URL for Viem public client */
|
|
18
|
+
rpcUrl?: string;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* A wallet provider that uses Privy's embedded wallets with delegation.
|
|
@@ -64,6 +66,12 @@ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvi
|
|
|
64
66
|
* @returns The name of the wallet provider.
|
|
65
67
|
*/
|
|
66
68
|
getName(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
71
|
+
*
|
|
72
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
73
|
+
*/
|
|
74
|
+
getPublicClient(): PublicClient;
|
|
67
75
|
/**
|
|
68
76
|
* Gets the balance of the wallet.
|
|
69
77
|
*
|
|
@@ -132,7 +140,7 @@ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvi
|
|
|
132
140
|
* Transfer the native asset of the network.
|
|
133
141
|
*
|
|
134
142
|
* @param to - The destination address.
|
|
135
|
-
* @param value - The amount to transfer in Wei.
|
|
143
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
136
144
|
* @returns The transaction hash.
|
|
137
145
|
*/
|
|
138
146
|
nativeTransfer(to: string, value: string): Promise<Hex>;
|
|
@@ -59,9 +59,10 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
59
59
|
if (!chain) {
|
|
60
60
|
throw new Error(`Chain with ID ${chainId} not found`);
|
|
61
61
|
}
|
|
62
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
62
63
|
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
63
64
|
chain,
|
|
64
|
-
transport: (0, viem_1.http)(),
|
|
65
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
65
66
|
}), "f");
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
@@ -142,6 +143,14 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
142
143
|
getName() {
|
|
143
144
|
return "privy_evm_embedded_wallet_provider";
|
|
144
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
148
|
+
*
|
|
149
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
150
|
+
*/
|
|
151
|
+
getPublicClient() {
|
|
152
|
+
return __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, "f");
|
|
153
|
+
}
|
|
145
154
|
/**
|
|
146
155
|
* Gets the balance of the wallet.
|
|
147
156
|
*
|
|
@@ -306,11 +315,11 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
306
315
|
* Transfer the native asset of the network.
|
|
307
316
|
*
|
|
308
317
|
* @param to - The destination address.
|
|
309
|
-
* @param value - The amount to transfer in Wei.
|
|
318
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
310
319
|
* @returns The transaction hash.
|
|
311
320
|
*/
|
|
312
321
|
async nativeTransfer(to, value) {
|
|
313
|
-
const valueInWei = (
|
|
322
|
+
const valueInWei = BigInt(value);
|
|
314
323
|
const valueHex = `0x${valueInWei.toString(16)}`;
|
|
315
324
|
const body = {
|
|
316
325
|
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
@@ -211,7 +211,7 @@ describe("PrivyEvmDelegatedEmbeddedWalletProvider", () => {
|
|
|
211
211
|
});
|
|
212
212
|
});
|
|
213
213
|
it("should transfer native tokens", async () => {
|
|
214
|
-
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "
|
|
214
|
+
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "1000000000000000000");
|
|
215
215
|
expect(result).toBe(MOCK_TRANSACTION_HASH);
|
|
216
216
|
});
|
|
217
217
|
it("should export wallet data", () => {
|
|
@@ -8,6 +8,8 @@ import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
|
8
8
|
export interface PrivyEvmWalletConfig extends PrivyWalletConfig {
|
|
9
9
|
/** Optional chain ID to connect to */
|
|
10
10
|
chainId?: string;
|
|
11
|
+
/** Optional RPC URL override for Viem wallet/public clients */
|
|
12
|
+
rpcUrl?: string;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* A wallet provider that uses Privy's server wallet API.
|
|
@@ -107,10 +107,11 @@ class PrivyEvmWalletProvider extends viemWalletProvider_1.ViemWalletProvider {
|
|
|
107
107
|
if (!chain) {
|
|
108
108
|
throw new Error(`Chain with ID ${chainId} not found`);
|
|
109
109
|
}
|
|
110
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
110
111
|
const walletClient = (0, viem_2.createWalletClient)({
|
|
111
112
|
account,
|
|
112
113
|
chain,
|
|
113
|
-
transport: (0, viem_2.http)(),
|
|
114
|
+
transport: rpcUrl ? (0, viem_2.http)(rpcUrl) : (0, viem_2.http)(),
|
|
114
115
|
});
|
|
115
116
|
return new PrivyEvmWalletProvider(walletClient, { ...config, walletId });
|
|
116
117
|
}
|
|
@@ -272,7 +272,7 @@ describe("PrivyEvmWalletProvider", () => {
|
|
|
272
272
|
expect(result).toBe("mock_result");
|
|
273
273
|
});
|
|
274
274
|
it("should transfer native tokens", async () => {
|
|
275
|
-
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "
|
|
275
|
+
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "1000000000000000000");
|
|
276
276
|
expect(result).toBe(MOCK_TRANSACTION_HASH);
|
|
277
277
|
});
|
|
278
278
|
it("should export wallet data", () => {
|
|
@@ -129,7 +129,7 @@ export declare class SolanaKeypairWalletProvider extends SvmWalletProvider {
|
|
|
129
129
|
* Transfer SOL from the wallet to another address
|
|
130
130
|
*
|
|
131
131
|
* @param to - The base58 encoded address to transfer the SOL to
|
|
132
|
-
* @param value - The amount
|
|
132
|
+
* @param value - The amount to transfer in atomic units (Lamports)
|
|
133
133
|
* @returns The signature
|
|
134
134
|
*/
|
|
135
135
|
nativeTransfer(to: string, value: string): Promise<string>;
|
|
@@ -231,16 +231,15 @@ class SolanaKeypairWalletProvider extends svmWalletProvider_1.SvmWalletProvider
|
|
|
231
231
|
* Transfer SOL from the wallet to another address
|
|
232
232
|
*
|
|
233
233
|
* @param to - The base58 encoded address to transfer the SOL to
|
|
234
|
-
* @param value - The amount
|
|
234
|
+
* @param value - The amount to transfer in atomic units (Lamports)
|
|
235
235
|
* @returns The signature
|
|
236
236
|
*/
|
|
237
237
|
async nativeTransfer(to, value) {
|
|
238
238
|
const initialBalance = await this.getBalance();
|
|
239
|
-
const
|
|
240
|
-
const lamports = BigInt(Math.floor(solAmount * web3_js_1.LAMPORTS_PER_SOL));
|
|
239
|
+
const lamports = BigInt(value);
|
|
241
240
|
// Check if we have enough balance (including estimated fees)
|
|
242
241
|
if (initialBalance < lamports + BigInt(5000)) {
|
|
243
|
-
throw new Error(`Insufficient balance. Have ${Number(initialBalance)
|
|
242
|
+
throw new Error(`Insufficient balance. Have ${Number(initialBalance)} lamports, need ${Number(lamports) + 5000} lamports (including fees)`);
|
|
244
243
|
}
|
|
245
244
|
const toPubkey = new web3_js_1.PublicKey(to);
|
|
246
245
|
const instructions = [
|
|
@@ -183,14 +183,16 @@ describe("SolanaKeypairWalletProvider", () => {
|
|
|
183
183
|
});
|
|
184
184
|
it("should transfer native tokens", async () => {
|
|
185
185
|
const destination = "EQJqzeeVEnm8rKWQJ5SMTtQBD4xEgixwgzNWKkpeFRZ9";
|
|
186
|
-
const signature = await wallet.nativeTransfer(destination, "0.1
|
|
186
|
+
const signature = await wallet.nativeTransfer(destination, "100000000"); // 0.1 SOL in lamports
|
|
187
187
|
expect(signature).toBe("signature123");
|
|
188
188
|
});
|
|
189
189
|
it("should handle insufficient balance when transferring", async () => {
|
|
190
190
|
const connection = wallet.getConnection();
|
|
191
191
|
connection.getBalance.mockResolvedValueOnce(100);
|
|
192
192
|
const destination = "EQJqzeeVEnm8rKWQJ5SMTtQBD4xEgixwgzNWKkpeFRZ9";
|
|
193
|
-
await expect(wallet.nativeTransfer(destination, "
|
|
193
|
+
await expect(wallet.nativeTransfer(destination, "1000000000")).rejects.toThrow(
|
|
194
|
+
// 1 SOL in lamports
|
|
195
|
+
"Insufficient balance");
|
|
194
196
|
});
|
|
195
197
|
it("should handle transaction failure when sending", async () => {
|
|
196
198
|
const connection = wallet.getConnection();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletClient as ViemWalletClient, TransactionRequest, ReadContractParameters, ReadContractReturnType, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
|
|
1
|
+
import { WalletClient as ViemWalletClient, TransactionRequest, PublicClient as ViemPublicClient, ReadContractParameters, ReadContractReturnType, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
|
|
2
2
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
/**
|
|
@@ -13,6 +13,10 @@ export interface ViemWalletProviderGasConfig {
|
|
|
13
13
|
* An internal multiplier on fee per gas estimation.
|
|
14
14
|
*/
|
|
15
15
|
feePerGasMultiplier?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Optional RPC URL override for Viem public client.
|
|
18
|
+
*/
|
|
19
|
+
rpcUrl?: string;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* A wallet provider that uses the Viem library.
|
|
@@ -72,6 +76,12 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
72
76
|
* @returns The name of the wallet provider.
|
|
73
77
|
*/
|
|
74
78
|
getName(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
81
|
+
*
|
|
82
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
83
|
+
*/
|
|
84
|
+
getPublicClient(): ViemPublicClient;
|
|
75
85
|
/**
|
|
76
86
|
* Gets the balance of the wallet.
|
|
77
87
|
*
|
|
@@ -96,7 +106,7 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
96
106
|
* Transfer the native asset of the network.
|
|
97
107
|
*
|
|
98
108
|
* @param to - The destination address.
|
|
99
|
-
* @param value - The amount to transfer in
|
|
109
|
+
* @param value - The amount to transfer in atomic units (Wei)
|
|
100
110
|
* @returns The transaction hash.
|
|
101
111
|
*/
|
|
102
112
|
nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
|