@coinbase/agentkit 0.0.0-nightly-20250904210426 → 0.0.0-nightly-20250905210407

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.
Files changed (53) hide show
  1. package/README.md +4 -0
  2. package/dist/action-providers/across/acrossActionProvider.js +3 -3
  3. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +3 -1
  4. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +4 -2
  5. package/dist/action-providers/compound/constants.d.ts +1 -1
  6. package/dist/action-providers/compound/constants.js +2 -2
  7. package/dist/action-providers/erc20/constants.d.ts +35 -135
  8. package/dist/action-providers/erc20/constants.js +37 -189
  9. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
  10. package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
  11. package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
  12. package/dist/action-providers/erc20/schemas.d.ts +25 -12
  13. package/dist/action-providers/erc20/schemas.js +34 -6
  14. package/dist/action-providers/erc20/utils.d.ts +19 -0
  15. package/dist/action-providers/erc20/utils.js +54 -0
  16. package/dist/action-providers/flaunch/constants.d.ts +1 -1
  17. package/dist/action-providers/flaunch/constants.js +2 -2
  18. package/dist/action-providers/moonwell/schemas.d.ts +2 -2
  19. package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
  20. package/dist/action-providers/morpho/schemas.d.ts +2 -2
  21. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +4 -4
  22. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +3 -3
  23. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +2 -2
  24. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +10 -10
  25. package/dist/action-providers/wallet/walletActionProvider.js +21 -10
  26. package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
  27. package/dist/action-providers/zeroX/zeroXActionProvider.js +2 -0
  28. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +1 -1
  29. package/dist/wallet-providers/cdpEvmWalletProvider.js +1 -1
  30. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +1 -1
  31. package/dist/wallet-providers/cdpSmartWalletProvider.js +1 -1
  32. package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
  33. package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
  34. package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
  35. package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +1 -1
  36. package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +1 -1
  37. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +1 -1
  38. package/dist/wallet-providers/legacyCdpWalletProvider.js +1 -1
  39. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +1 -1
  40. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +2 -2
  41. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
  42. package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
  43. package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
  44. package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
  45. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
  46. package/dist/wallet-providers/viemWalletProvider.d.ts +1 -1
  47. package/dist/wallet-providers/viemWalletProvider.js +2 -2
  48. package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
  49. package/dist/wallet-providers/walletProvider.d.ts +1 -1
  50. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +1 -1
  51. package/dist/wallet-providers/zeroDevWalletProvider.js +4 -4
  52. package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
  53. package/package.json +1 -1
@@ -13,12 +13,12 @@ exports.morphoActionProvider = exports.MorphoActionProvider = exports.SUPPORTED_
13
13
  const zod_1 = require("zod");
14
14
  const decimal_js_1 = require("decimal.js");
15
15
  const viem_1 = require("viem");
16
- const constants_1 = require("../erc20/constants");
16
+ const viem_2 = require("viem");
17
17
  const actionProvider_1 = require("../actionProvider");
18
18
  const wallet_providers_1 = require("../../wallet-providers");
19
19
  const actionDecorator_1 = require("../actionDecorator");
20
20
  const utils_1 = require("../../utils");
21
- const constants_2 = require("./constants");
21
+ const constants_1 = require("./constants");
22
22
  const schemas_1 = require("./schemas");
23
23
  exports.SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
24
24
  /**
@@ -53,7 +53,7 @@ class MorphoActionProvider extends actionProvider_1.ActionProvider {
53
53
  try {
54
54
  const decimals = await wallet.readContract({
55
55
  address: args.tokenAddress,
56
- abi: constants_1.abi,
56
+ abi: viem_2.erc20Abi,
57
57
  functionName: "decimals",
58
58
  args: [],
59
59
  });
@@ -63,7 +63,7 @@ class MorphoActionProvider extends actionProvider_1.ActionProvider {
63
63
  return `Error approving Morpho Vault as spender: ${approvalResult}`;
64
64
  }
65
65
  const data = (0, viem_1.encodeFunctionData)({
66
- abi: constants_2.METAMORPHO_ABI,
66
+ abi: constants_1.METAMORPHO_ABI,
67
67
  functionName: "deposit",
68
68
  args: [atomicAssets, args.receiver],
69
69
  });
@@ -91,7 +91,7 @@ class MorphoActionProvider extends actionProvider_1.ActionProvider {
91
91
  }
92
92
  try {
93
93
  const data = (0, viem_1.encodeFunctionData)({
94
- abi: constants_2.METAMORPHO_ABI,
94
+ abi: constants_1.METAMORPHO_ABI,
95
95
  functionName: "withdraw",
96
96
  args: [BigInt(args.assets), args.receiver, args.receiver],
97
97
  });
@@ -8,14 +8,14 @@ export declare const DepositSchema: z.ZodObject<{
8
8
  tokenAddress: z.ZodString;
9
9
  vaultAddress: z.ZodString;
10
10
  }, "strip", z.ZodTypeAny, {
11
+ tokenAddress: string;
11
12
  receiver: string;
12
13
  assets: string;
13
- tokenAddress: string;
14
14
  vaultAddress: string;
15
15
  }, {
16
+ tokenAddress: string;
16
17
  receiver: string;
17
18
  assets: string;
18
- tokenAddress: string;
19
19
  vaultAddress: string;
20
20
  }>;
21
21
  /**
@@ -17,7 +17,7 @@ const viem_1 = require("viem");
17
17
  const actionProvider_1 = require("../actionProvider");
18
18
  const wallet_providers_1 = require("../../wallet-providers");
19
19
  const actionDecorator_1 = require("../actionDecorator");
20
- const constants_2 = require("../erc20/constants");
20
+ const viem_2 = require("viem");
21
21
  const parseLogs_1 = require("./utils/parseLogs");
22
22
  /**
23
23
  * SuperfluidSuperTokenCreatorActionProvider is an action provider for Superfluid interactions.
@@ -47,19 +47,19 @@ class SuperfluidSuperTokenCreatorActionProvider extends actionProvider_1.ActionP
47
47
  try {
48
48
  const decimals = await walletProvider.readContract({
49
49
  address: args.erc20TokenAddress,
50
- abi: constants_2.abi,
50
+ abi: viem_2.erc20Abi,
51
51
  functionName: "decimals",
52
52
  args: [],
53
53
  });
54
54
  const name = await walletProvider.readContract({
55
55
  address: args.erc20TokenAddress,
56
- abi: constants_2.abi,
56
+ abi: viem_2.erc20Abi,
57
57
  functionName: "name",
58
58
  args: [],
59
59
  });
60
60
  const symbol = await walletProvider.readContract({
61
61
  address: args.erc20TokenAddress,
62
- abi: constants_2.abi,
62
+ abi: viem_2.erc20Abi,
63
63
  functionName: "symbol",
64
64
  args: [],
65
65
  });
@@ -17,7 +17,7 @@ const viem_1 = require("viem");
17
17
  const actionProvider_1 = require("../actionProvider");
18
18
  const wallet_providers_1 = require("../../wallet-providers");
19
19
  const actionDecorator_1 = require("../actionDecorator");
20
- const constants_2 = require("../erc20/constants");
20
+ const viem_2 = require("viem");
21
21
  /**
22
22
  * SuperfluidStreamActionProvider is an action provider for wrapping superfluid token.
23
23
  */
@@ -48,13 +48,13 @@ class SuperfluidWrapperActionProvider extends actionProvider_1.ActionProvider {
48
48
  try {
49
49
  const decimals = await walletProvider.readContract({
50
50
  address: args.erc20TokenAddress,
51
- abi: constants_2.abi,
51
+ abi: viem_2.erc20Abi,
52
52
  functionName: "decimals",
53
53
  args: [],
54
54
  });
55
55
  const amount = (0, viem_1.parseUnits)(String(args.wrapAmount), Number(decimals));
56
56
  const approveData = (0, viem_1.encodeFunctionData)({
57
- abi: constants_2.abi,
57
+ abi: viem_2.erc20Abi,
58
58
  functionName: "approve",
59
59
  args: [args.superTokenAddress, amount],
60
60
  });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const viem_1 = require("viem");
4
4
  const constants_1 = require("./constants");
5
5
  const superfluidWrapperActionProvider_1 = require("./superfluidWrapperActionProvider");
6
- const constants_2 = require("../erc20/constants");
6
+ const viem_2 = require("viem");
7
7
  describe("SuperfluidWrapperActionProvider", () => {
8
8
  const MOCK_ADDRESS = "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83";
9
9
  const MOCK_ERC20_CONTRACT = "0x1234567890123456789012345678901234567890";
@@ -45,7 +45,7 @@ describe("SuperfluidWrapperActionProvider", () => {
45
45
  await actionProvider.wrapToken(mockWallet, args);
46
46
  const amount = (0, viem_1.parseUnits)(String(args.wrapAmount), Number(MOCK_DECIMALS));
47
47
  const approveData = (0, viem_1.encodeFunctionData)({
48
- abi: constants_2.abi,
48
+ abi: viem_2.erc20Abi,
49
49
  functionName: "approve",
50
50
  args: [MOCK_SUPERTOKEN_CONTRACT, amount],
51
51
  });
@@ -15,9 +15,9 @@ const actionProvider_1 = require("../actionProvider");
15
15
  const actionDecorator_1 = require("../actionDecorator");
16
16
  const schemas_1 = require("./schemas");
17
17
  const constants_1 = require("./constants");
18
- const constants_2 = require("../erc20/constants");
19
- const wallet_providers_1 = require("../../wallet-providers");
20
18
  const viem_1 = require("viem");
19
+ const wallet_providers_1 = require("../../wallet-providers");
20
+ const viem_2 = require("viem");
21
21
  /**
22
22
  * Action provider for TrueMarkets interactions.
23
23
  */
@@ -288,25 +288,25 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
288
288
  const balanceCalls = [
289
289
  {
290
290
  address: payToken,
291
- abi: constants_2.abi,
291
+ abi: viem_1.erc20Abi,
292
292
  functionName: "balanceOf",
293
293
  args: [yesPool],
294
294
  },
295
295
  {
296
296
  address: yesToken,
297
- abi: constants_2.abi,
297
+ abi: viem_1.erc20Abi,
298
298
  functionName: "balanceOf",
299
299
  args: [yesPool],
300
300
  },
301
301
  {
302
302
  address: payToken,
303
- abi: constants_2.abi,
303
+ abi: viem_1.erc20Abi,
304
304
  functionName: "balanceOf",
305
305
  args: [noPool],
306
306
  },
307
307
  {
308
308
  address: noToken,
309
- abi: constants_2.abi,
309
+ abi: viem_1.erc20Abi,
310
310
  functionName: "balanceOf",
311
311
  args: [noPool],
312
312
  },
@@ -346,10 +346,10 @@ class TrueMarketsActionProvider extends actionProvider_1.ActionProvider {
346
346
  const yesPrice = calculatePrice(yesSqrtPriceX96, isYesToken0, payDecimals, yesNoTokenDecimals_);
347
347
  const noPrice = calculatePrice(noSqrtPriceX96, isNoToken0, payDecimals, yesNoTokenDecimals_);
348
348
  // Calculate TVL using token balances
349
- const yesPoolStableValue = Number((0, viem_1.formatUnits)(yesPoolStableBalance || 0n, payDecimals));
350
- const yesPoolTokenValue = Number((0, viem_1.formatUnits)(yesPoolTokenBalance || 0n, yesNoTokenDecimals_)) * yesPrice;
351
- const noPoolStableValue = Number((0, viem_1.formatUnits)(noPoolStableBalance || 0n, payDecimals));
352
- const noPoolTokenValue = Number((0, viem_1.formatUnits)(noPoolTokenBalance || 0n, yesNoTokenDecimals_)) * noPrice;
349
+ const yesPoolStableValue = Number((0, viem_2.formatUnits)(yesPoolStableBalance || 0n, payDecimals));
350
+ const yesPoolTokenValue = Number((0, viem_2.formatUnits)(yesPoolTokenBalance || 0n, yesNoTokenDecimals_)) * yesPrice;
351
+ const noPoolStableValue = Number((0, viem_2.formatUnits)(noPoolStableBalance || 0n, payDecimals));
352
+ const noPoolTokenValue = Number((0, viem_2.formatUnits)(noPoolTokenBalance || 0n, yesNoTokenDecimals_)) * noPrice;
353
353
  const yesTVL = yesPoolStableValue + yesPoolTokenValue;
354
354
  const noTVL = noPoolStableValue + noPoolTokenValue;
355
355
  const totalTVL = yesTVL + noTVL;
@@ -14,12 +14,25 @@ const zod_1 = require("zod");
14
14
  const actionDecorator_1 = require("../actionDecorator");
15
15
  const actionProvider_1 = require("../actionProvider");
16
16
  const wallet_providers_1 = require("../../wallet-providers");
17
+ const viem_1 = require("viem");
17
18
  const schemas_1 = require("./schemas");
18
19
  const PROTOCOL_FAMILY_TO_TERMINOLOGY = {
19
- evm: { unit: "WEI", displayUnit: "ETH", type: "Transaction hash", verb: "transaction" },
20
- svm: { unit: "LAMPORTS", displayUnit: "SOL", type: "Signature", verb: "transfer" },
20
+ evm: {
21
+ unit: "WEI",
22
+ displayUnit: "ETH",
23
+ decimals: 18,
24
+ type: "Transaction hash",
25
+ verb: "transaction",
26
+ },
27
+ svm: { unit: "LAMPORTS", displayUnit: "SOL", decimals: 9, type: "Signature", verb: "transfer" },
28
+ };
29
+ const DEFAULT_TERMINOLOGY = {
30
+ unit: "",
31
+ displayUnit: "",
32
+ decimals: 0,
33
+ type: "Hash",
34
+ verb: "transfer",
21
35
  };
22
- const DEFAULT_TERMINOLOGY = { unit: "", displayUnit: "", type: "Hash", verb: "transfer" };
23
36
  /**
24
37
  * WalletActionProvider provides actions for getting basic wallet information.
25
38
  */
@@ -61,6 +74,7 @@ class WalletActionProvider extends actionProvider_1.ActionProvider {
61
74
  ` * Network ID: ${network.networkId || "N/A"}`,
62
75
  ` * Chain ID: ${network.chainId || "N/A"}`,
63
76
  `- Native Balance: ${balance.toString()} ${terminology.unit}`,
77
+ `- Native Balance: ${(0, viem_1.formatUnits)(balance, terminology.decimals)} ${terminology.displayUnit}`,
64
78
  ].join("\n");
65
79
  }
66
80
  catch (error) {
@@ -81,7 +95,8 @@ class WalletActionProvider extends actionProvider_1.ActionProvider {
81
95
  if (protocolFamily === "evm" && !args.to.startsWith("0x")) {
82
96
  args.to = `0x${args.to}`;
83
97
  }
84
- const result = await walletProvider.nativeTransfer(args.to, args.value);
98
+ const amountInAtomicUnits = (0, viem_1.parseUnits)(args.value, terminology.decimals);
99
+ const result = await walletProvider.nativeTransfer(args.to, amountInAtomicUnits.toString());
85
100
  return [
86
101
  `Transferred ${args.value} ${terminology.displayUnit} to ${args.to}`,
87
102
  `${terminology.type}: ${result}`,
@@ -115,15 +130,11 @@ __decorate([
115
130
  (0, actionDecorator_1.CreateAction)({
116
131
  name: "native_transfer",
117
132
  description: `
118
- This tool will transfer native tokens from the wallet to another onchain address.
133
+ This tool will transfer (send) native tokens from the wallet to another onchain address.
119
134
 
120
135
  It takes the following inputs:
121
- - amount: The amount to transfer in whole units (e.g. 1 ETH, 0.1 SOL)
136
+ - amount: The amount to transfer in whole units (e.g. 4.2 ETH, 0.1 SOL)
122
137
  - destination: The address to receive the funds
123
-
124
- Important notes:
125
- - Ensure sufficient balance of the input asset before transferring
126
- - Ensure there is sufficient native token balance for gas fees
127
138
  `,
128
139
  schema: schemas_1.NativeTransferSchema,
129
140
  }),
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const walletActionProvider_1 = require("./walletActionProvider");
4
4
  const schemas_1 = require("./schemas");
5
+ const viem_1 = require("viem");
5
6
  describe("Wallet Action Provider", () => {
6
7
  const MOCK_ADDRESS = "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83";
7
8
  const MOCK_ETH_BALANCE = 1000000000000000000n;
@@ -47,6 +48,7 @@ describe("Wallet Action Provider", () => {
47
48
  ` * Network ID: ${MOCK_EVM_NETWORK.networkId}`,
48
49
  ` * Chain ID: ${MOCK_EVM_NETWORK.chainId}`,
49
50
  `- Native Balance: ${MOCK_ETH_BALANCE.toString()} WEI`,
51
+ `- Native Balance: ${(0, viem_1.formatUnits)(MOCK_ETH_BALANCE, 18)} ETH`,
50
52
  ].join("\n");
51
53
  expect(response).toBe(expectedResponse);
52
54
  });
@@ -63,6 +65,7 @@ describe("Wallet Action Provider", () => {
63
65
  ` * Network ID: ${MOCK_SOLANA_NETWORK.networkId}`,
64
66
  ` * Chain ID: N/A`,
65
67
  `- Native Balance: ${MOCK_SOL_BALANCE.toString()} LAMPORTS`,
68
+ `- Native Balance: ${(0, viem_1.formatUnits)(MOCK_SOL_BALANCE, 9)} SOL`,
66
69
  ].join("\n");
67
70
  expect(response).toBe(expectedResponse);
68
71
  });
@@ -79,6 +82,7 @@ describe("Wallet Action Provider", () => {
79
82
  ` * Network ID: ${MOCK_UNKNOWN_NETWORK.networkId}`,
80
83
  ` * Chain ID: N/A`,
81
84
  `- Native Balance: ${MOCK_ETH_BALANCE.toString()} `,
85
+ `- Native Balance: ${MOCK_ETH_BALANCE.toString()} `,
82
86
  ].join("\n");
83
87
  expect(response).toBe(expectedResponse);
84
88
  });
@@ -125,7 +129,7 @@ describe("Wallet Action Provider", () => {
125
129
  value: MOCK_AMOUNT,
126
130
  };
127
131
  const response = await actionProvider.nativeTransfer(mockWallet, args);
128
- expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, MOCK_AMOUNT);
132
+ expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, (0, viem_1.parseUnits)(MOCK_AMOUNT, 18).toString());
129
133
  expect(response).toBe(`Transferred ${MOCK_AMOUNT} ETH to ${MOCK_DESTINATION}\nTransaction hash: ${MOCK_TRANSACTION_HASH}`);
130
134
  });
131
135
  it("should successfully transfer SOL", async () => {
@@ -136,7 +140,7 @@ describe("Wallet Action Provider", () => {
136
140
  value: MOCK_AMOUNT,
137
141
  };
138
142
  const response = await actionProvider.nativeTransfer(mockWallet, args);
139
- expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, MOCK_AMOUNT);
143
+ expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, (0, viem_1.parseUnits)(MOCK_AMOUNT, 9).toString());
140
144
  expect(response).toBe(`Transferred ${MOCK_AMOUNT} SOL to ${MOCK_DESTINATION}\nSignature: ${MOCK_SIGNATURE}`);
141
145
  });
142
146
  it("should handle ETH transfer errors", async () => {
@@ -357,6 +357,7 @@ Important notes:
357
357
  - This only fetches a price quote and does not execute a swap
358
358
  - Supported on all EVM networks compatible with 0x API
359
359
  - Use sellToken units exactly as provided, do not convert to wei or any other units
360
+ - Never assume token or address, they have to be provided as inputs. If only token symbol is provided, use the get_token_address tool if available to get the token address first
360
361
  `,
361
362
  schema: schemas_1.GetSwapPriceSchema,
362
363
  }),
@@ -388,6 +389,7 @@ Important notes:
388
389
  - First fetch a price quote and only execute swap if you are happy with the indicated price
389
390
  - Supported on all EVM networks compatible with 0x API
390
391
  - Use sellToken units exactly as provided, do not convert to wei or any other units
392
+ - Never assume token or address, they have to be provided as inputs. If only token symbol is provided, use the get_token_address tool if available to get the token address first
391
393
  `,
392
394
  schema: schemas_1.ExecuteSwapSchema,
393
395
  }),
@@ -113,7 +113,7 @@ export declare class CdpEvmWalletProvider extends EvmWalletProvider implements W
113
113
  * Transfer the native asset of the network.
114
114
  *
115
115
  * @param to - The destination address.
116
- * @param value - The amount to transfer in Wei.
116
+ * @param value - The amount to transfer in atomic units (Wei).
117
117
  * @returns The transaction hash.
118
118
  */
119
119
  nativeTransfer(to: Address, value: string): Promise<Hex>;
@@ -228,7 +228,7 @@ class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
228
228
  * Transfer the native asset of the network.
229
229
  *
230
230
  * @param to - The destination address.
231
- * @param value - The amount to transfer in Wei.
231
+ * @param value - The amount to transfer in atomic units (Wei).
232
232
  * @returns The transaction hash.
233
233
  */
234
234
  async nativeTransfer(to, value) {
@@ -122,7 +122,7 @@ export declare class CdpSmartWalletProvider extends EvmWalletProvider implements
122
122
  * Transfer the native asset of the network using smart wallet.
123
123
  *
124
124
  * @param to - The destination address.
125
- * @param value - The amount to transfer in Wei.
125
+ * @param value - The amount to transfer in atomic units (Wei).
126
126
  * @returns The user operation hash.
127
127
  */
128
128
  nativeTransfer(to: Address, value: string): Promise<Hex>;
@@ -259,7 +259,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
259
259
  * Transfer the native asset of the network using smart wallet.
260
260
  *
261
261
  * @param to - The destination address.
262
- * @param value - The amount to transfer in Wei.
262
+ * @param value - The amount to transfer in atomic units (Wei).
263
263
  * @returns The user operation hash.
264
264
  */
265
265
  async nativeTransfer(to, value) {
@@ -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 of SOL to transfer (as a decimal string, e.g. "0.0001")
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 signedTransaction = await __classPrivateFieldGet(this, _CdpSolanaWalletProvider_cdp, "f").solana.signTransaction({
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
- transaction.addSignature(this.getPublicKey(), Buffer.from(signedTransaction.signature, "base64"));
155
- return transaction;
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 of SOL to transfer (as a decimal string, e.g. "0.0001")
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 solAmount = parseFloat(value);
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) / web3_js_1.LAMPORTS_PER_SOL} SOL, need ${solAmount + 0.000005} SOL (including fees)`);
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: jest.fn().mockImplementation(() => ({
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
- .fn()
74
- .mockImplementation(async () => ({ signature: MOCK_SIGNATURE }));
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
- .fn()
127
- .mockResolvedValue({ signature: MOCK_SIGNATURE });
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 = "1.0";
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 = "1.0";
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 () => {
@@ -177,7 +177,7 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
177
177
  * Transfer the native asset of the network.
178
178
  *
179
179
  * @param to - The destination address.
180
- * @param value - The amount to transfer in Wei.
180
+ * @param value - The amount to transfer in atomic units (Wei).
181
181
  * @returns The transaction hash.
182
182
  */
183
183
  nativeTransfer(to: Address, value: string): Promise<Hex>;
@@ -288,7 +288,7 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
288
288
  * Transfer the native asset of the network.
289
289
  *
290
290
  * @param to - The destination address.
291
- * @param value - The amount to transfer in Wei.
291
+ * @param value - The amount to transfer in atomic units (Wei).
292
292
  * @returns The transaction hash.
293
293
  */
294
294
  async nativeTransfer(to, value) {
@@ -231,7 +231,7 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
231
231
  * Transfer the native asset of the network.
232
232
  *
233
233
  * @param to - The destination address.
234
- * @param value - The amount to transfer in Wei.
234
+ * @param value - The amount to transfer in atomic units (Wei).
235
235
  * @returns The transaction hash.
236
236
  */
237
237
  nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
@@ -372,7 +372,7 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
372
372
  * Transfer the native asset of the network.
373
373
  *
374
374
  * @param to - The destination address.
375
- * @param value - The amount to transfer in Wei.
375
+ * @param value - The amount to transfer in atomic units (Wei).
376
376
  * @returns The transaction hash.
377
377
  */
378
378
  async nativeTransfer(to, value) {
@@ -140,7 +140,7 @@ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvi
140
140
  * Transfer the native asset of the network.
141
141
  *
142
142
  * @param to - The destination address.
143
- * @param value - The amount to transfer in Wei.
143
+ * @param value - The amount to transfer in atomic units (Wei).
144
144
  * @returns The transaction hash.
145
145
  */
146
146
  nativeTransfer(to: string, value: string): Promise<Hex>;
@@ -315,11 +315,11 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
315
315
  * Transfer the native asset of the network.
316
316
  *
317
317
  * @param to - The destination address.
318
- * @param value - The amount to transfer in Wei.
318
+ * @param value - The amount to transfer in atomic units (Wei).
319
319
  * @returns The transaction hash.
320
320
  */
321
321
  async nativeTransfer(to, value) {
322
- const valueInWei = (0, viem_1.parseEther)(value);
322
+ const valueInWei = BigInt(value);
323
323
  const valueHex = `0x${valueInWei.toString(16)}`;
324
324
  const body = {
325
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", "1.0");
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", () => {
@@ -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", "1.0");
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 of SOL to transfer (as a decimal string, e.g. "0.0001")
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 of SOL to transfer (as a decimal string, e.g. "0.0001")
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 solAmount = parseFloat(value);
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) / web3_js_1.LAMPORTS_PER_SOL} SOL, need ${solAmount + 0.000005} SOL (including fees)`);
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, "1.0")).rejects.toThrow("Insufficient balance");
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();
@@ -106,7 +106,7 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
106
106
  * Transfer the native asset of the network.
107
107
  *
108
108
  * @param to - The destination address.
109
- * @param value - The amount to transfer in whole units (e.g. ETH)
109
+ * @param value - The amount to transfer in atomic units (Wei)
110
110
  * @returns The transaction hash.
111
111
  */
112
112
  nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;