@deserialize/multi-vm-wallet 1.3.2 → 1.3.4

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 (99) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/dist/IChainWallet.d.ts +2 -0
  3. package/dist/IChainWallet.js.map +1 -1
  4. package/dist/constant.js +60 -16
  5. package/dist/constant.js.map +1 -1
  6. package/dist/evm/aa-service/index.d.ts +1 -1
  7. package/dist/evm/aa-service/index.js +1 -2
  8. package/dist/evm/aa-service/index.js.map +1 -1
  9. package/dist/evm/aa-service/lib/kernel-account.d.ts +1 -1
  10. package/dist/evm/aa-service/lib/kernel-account.js +22 -6
  11. package/dist/evm/aa-service/lib/kernel-account.js.map +1 -1
  12. package/dist/evm/aa-service/lib/session-keys.d.ts +14 -17
  13. package/dist/evm/aa-service/lib/session-keys.js +40 -58
  14. package/dist/evm/aa-service/lib/session-keys.js.map +1 -1
  15. package/dist/evm/aa-service/lib/type.d.ts +2 -1
  16. package/dist/evm/aa-service/lib/type.js.map +1 -1
  17. package/dist/evm/aa-service/services/account-abstraction.d.ts +3 -29
  18. package/dist/evm/aa-service/services/account-abstraction.js +3 -67
  19. package/dist/evm/aa-service/services/account-abstraction.js.map +1 -1
  20. package/dist/evm/aa-service/services/bundler.js +2 -1
  21. package/dist/evm/aa-service/services/bundler.js.map +1 -1
  22. package/dist/evm/evm.d.ts +163 -1
  23. package/dist/evm/evm.js +259 -0
  24. package/dist/evm/evm.js.map +1 -1
  25. package/dist/evm/smartWallet.d.ts +11 -43
  26. package/dist/evm/smartWallet.js +136 -116
  27. package/dist/evm/smartWallet.js.map +1 -1
  28. package/dist/evm/utils.js +0 -1
  29. package/dist/evm/utils.js.map +1 -1
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/price.d.ts +2 -0
  34. package/dist/price.js +33 -0
  35. package/dist/price.js.map +1 -0
  36. package/dist/price.types.d.ts +38 -0
  37. package/dist/price.types.js +4 -0
  38. package/dist/price.types.js.map +1 -0
  39. package/dist/privacy/artifact-manager.d.ts +117 -0
  40. package/dist/privacy/artifact-manager.js +251 -0
  41. package/dist/privacy/artifact-manager.js.map +1 -0
  42. package/dist/privacy/broadcaster-client.d.ts +166 -0
  43. package/dist/privacy/broadcaster-client.js +261 -0
  44. package/dist/privacy/broadcaster-client.js.map +1 -0
  45. package/dist/privacy/index.d.ts +34 -0
  46. package/dist/privacy/index.js +56 -0
  47. package/dist/privacy/index.js.map +1 -0
  48. package/dist/privacy/network-config.d.ts +57 -0
  49. package/dist/privacy/network-config.js +118 -0
  50. package/dist/privacy/network-config.js.map +1 -0
  51. package/dist/privacy/poi-helper.d.ts +161 -0
  52. package/dist/privacy/poi-helper.js +249 -0
  53. package/dist/privacy/poi-helper.js.map +1 -0
  54. package/dist/privacy/railgun-engine.d.ts +135 -0
  55. package/dist/privacy/railgun-engine.js +205 -0
  56. package/dist/privacy/railgun-engine.js.map +1 -0
  57. package/dist/privacy/railgun-privacy-wallet.d.ts +288 -0
  58. package/dist/privacy/railgun-privacy-wallet.js +539 -0
  59. package/dist/privacy/railgun-privacy-wallet.js.map +1 -0
  60. package/dist/privacy/types.d.ts +229 -0
  61. package/dist/privacy/types.js +26 -0
  62. package/dist/privacy/types.js.map +1 -0
  63. package/dist/savings/savings-manager.d.ts +126 -0
  64. package/dist/savings/savings-manager.js +234 -0
  65. package/dist/savings/savings-manager.js.map +1 -0
  66. package/dist/savings/smart-savings.d.ts +74 -0
  67. package/dist/savings/smart-savings.js +152 -0
  68. package/dist/savings/smart-savings.js.map +1 -0
  69. package/dist/savings/types.d.ts +125 -0
  70. package/dist/savings/types.js +9 -0
  71. package/dist/savings/types.js.map +1 -0
  72. package/dist/svm/svm.d.ts +18 -0
  73. package/dist/svm/svm.js +35 -0
  74. package/dist/svm/svm.js.map +1 -1
  75. package/dist/test.js +53 -15
  76. package/dist/test.js.map +1 -1
  77. package/dist/vm.d.ts +14 -0
  78. package/dist/vm.js.map +1 -1
  79. package/package.json +2 -1
  80. package/utils/IChainWallet.ts +2 -0
  81. package/utils/constant.ts +63 -16
  82. package/utils/evm/aa-service/index.ts +0 -1
  83. package/utils/evm/aa-service/lib/kernel-account.ts +23 -8
  84. package/utils/evm/aa-service/lib/session-keys.ts +58 -60
  85. package/utils/evm/aa-service/lib/type.ts +2 -1
  86. package/utils/evm/aa-service/services/account-abstraction.ts +10 -76
  87. package/utils/evm/aa-service/services/bundler.ts +2 -1
  88. package/utils/evm/evm.ts +317 -0
  89. package/utils/evm/smartWallet.ts +118 -128
  90. package/utils/evm/utils.ts +1 -1
  91. package/utils/index.ts +1 -0
  92. package/utils/price.ts +37 -0
  93. package/utils/price.types.ts +45 -0
  94. package/utils/savings/savings-manager.ts +271 -0
  95. package/utils/savings/smart-savings.ts +184 -0
  96. package/utils/savings/types.ts +135 -0
  97. package/utils/svm/svm.ts +43 -2
  98. package/utils/test.ts +84 -19
  99. package/utils/vm.ts +12 -1
package/utils/svm/svm.ts CHANGED
@@ -24,6 +24,8 @@ import {
24
24
  import BN from "bn.js";
25
25
  import nacl from "tweetnacl";
26
26
  import base58 from "bs58";
27
+ import { fetchPrices } from "../price";
28
+ import { PriceResponse } from "../price.types";
27
29
  import { getSVMTransactionHistory, SVMTransactionHistoryItem } from "./transactionParsing";
28
30
 
29
31
 
@@ -76,12 +78,37 @@ export class SVMVM extends VM<PublicKey, Keypair, Connection> {
76
78
  const privateKey = SVMDeriveChildPrivateKey(_seed, index, derivationPath);
77
79
  return { privateKey, index };
78
80
  }
81
+
82
+ /**
83
+ * Derive a savings account using BIP-44 account index
84
+ *
85
+ * Uses the pattern: m/44'/501'/accountIndex'/0/0
86
+ * - Main wallet: m/44'/501'/0'/0/0 (account index 0)
87
+ * - Savings 1: m/44'/501'/1'/0/0 (account index 1)
88
+ * - Savings 2: m/44'/501'/2'/0/0 (account index 2)
89
+ *
90
+ * @param accountIndex - The BIP-44 account index (0 for main, 1+ for savings)
91
+ * @returns Object containing privateKey (Keypair), address (PublicKey), and derivation path
92
+ */
93
+ deriveSavingsAccount(accountIndex: number): { privateKey: Keypair; address: PublicKey; derivationPath: string } {
94
+ // Use fixed address index 0 for savings accounts
95
+ // Vary only the account index (3rd position in BIP-44)
96
+ const derivationPath = `m/44'/501'/${accountIndex}'/0/0`;
97
+
98
+ // Derive the keypair using the account index in the path
99
+ const keypair = SVMDeriveChildPrivateKey(this.seed, 0, `m/44'/501'/${accountIndex}'/0/`);
100
+
101
+ return {
102
+ privateKey: keypair,
103
+ address: keypair.publicKey,
104
+ derivationPath
105
+ };
106
+ }
107
+
79
108
  static fromMnemonic(mnemonic: string): VM<PublicKey, Keypair, Connection> {
80
109
  const seed = VM.mnemonicToSeed(mnemonic)
81
110
  return new SVMVM(seed)
82
111
  }
83
-
84
-
85
112
  }
86
113
 
87
114
  export class SVMChainWallet extends ChainWallet<PublicKey, Keypair, Connection> {
@@ -175,6 +202,20 @@ export class SVMChainWallet extends ChainWallet<PublicKey, Keypair, Connection>
175
202
  return await SVMVM.getTokenInfo(tokenAddress, this.connection!)
176
203
  }
177
204
 
205
+ async getPrices(tokenAddresses: string[]): Promise<PriceResponse> {
206
+ const result = await fetchPrices({
207
+ vm: 'SVM',
208
+ chainId: this.config.chainId,
209
+ tokenAddresses,
210
+ });
211
+
212
+ if (result.error) {
213
+ throw new Error(result.error.message);
214
+ }
215
+
216
+ return result.data as PriceResponse;
217
+ }
218
+
178
219
  async swap(fromToken: TokenInfo, toToken: PublicKey, amount: number, slippage: number = 50): Promise<TransactionResult> {
179
220
  try {
180
221
  if (amount <= 0) {
package/utils/test.ts CHANGED
@@ -11,31 +11,30 @@ import { ChainWalletConfig } from "./types";
11
11
  import { discoverNFTs, EVMChainWallet } from "./evm";
12
12
  import { } from "./svm/transactionParsing";
13
13
  import { getEVMTransactionHistory } from "./evm/transactionParsing";
14
- import { createPublicClient, encodeFunctionData, Hex, http, parseAbi, parseUnits, PublicClient } from "viem";
14
+ import { createPublicClient, encodeFunctionData, Hex, http, parseAbi, parseUnits, PublicClient, zeroAddress } from "viem";
15
15
  import { base, baseGoerli } from "viem/chains";
16
16
  import { discoverTokens, fetchWalletNfts, getTokenInfo } from "./svm/utils";
17
- import { JsonRpcProvider } from "ethers";
17
+ import { JsonRpcProvider, N } from "ethers";
18
18
 
19
19
  import { } from "@solana/spl-token-metadata"
20
20
  import { entryPoint07Address } from "viem/account-abstraction";
21
21
 
22
22
  import { KERNEL_V3_3, KernelVersionToAddressesMap } from '@zerodev/sdk/constants';
23
+ import { deserializeSessionKey } from "./evm/aa-service";
24
+ import { toSpendingLimitHook } from "@zerodev/hooks"
23
25
  // const mnemonic = GenerateNewMnemonic()
24
26
 
25
27
 
26
28
  // console.log('mnemonic: ', mnemonic);
27
29
 
28
30
  // const seed = VM.mnemonicToSeed(mnemonic)
29
- const pKey = "4QxETeX9pndiF1XNghUiDTnZnHq3cfjmuPLBJysrgocsLq1yb8w96aPWALa8ZnRZWmDU4wM8Tg8d1ZRVVByj7uXE"
31
+ const pKey = ""
30
32
 
31
33
  const testUserKeyPair = Keypair.fromSecretKey(base58.decode(pKey));
32
34
  // const x = testUserKeyPair instanceof Keypair;
33
- const evePrivateKey = "0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318"
34
- const evmPrivateKey2 = "0x0123456789012345678901234567890123456789012345678901234567890123"
35
- const ogPrivKey = "d2d3f7117aa9a4c6e5d4affedd8a5ea624ffd82b2a1de81509e5913709b1ea72"
36
35
 
37
- const evmPrivKey = "0xc9ca95aa5f40bae8b0f741ec89acc07b837590b2f9f818d3439df98c6e4f8dbe"
38
- const evmPrivateKeyExposed = "0x92cccc7792024dcac5992e5d2986dade41770acfd3dab0fe98ee953ed1bf0c3a"
36
+ const evmPrivKey = ""
37
+ const evmPrivateKeyExposed = ""
39
38
  // const vm = new SVMVM(seed)
40
39
 
41
40
 
@@ -59,7 +58,7 @@ const chainConfig: ChainWalletConfig = {
59
58
  const evmChainConfig: ChainWalletConfig = {
60
59
  chainId: 8453,
61
60
  name: "Base",
62
- // rpcUrl: "https://eth-mainnet.g.alchemy.com/v2/lhoyb3hc9ccT9NA_y2cfA",
61
+ // rpcUrl: "https://base-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
63
62
  rpcUrl: base.rpcUrls.default.http[0],
64
63
  explorerUrl: "https://explorer.ethereum.com",
65
64
  nativeToken: { name: "Ethereum", symbol: "ETH", decimals: 18 },
@@ -70,7 +69,8 @@ const evmChainConfig: ChainWalletConfig = {
70
69
  enabled: true,
71
70
  entryPoints: [
72
71
  {
73
- address: entryPoint07Address,
72
+ address: entryPoint07Address
73
+ ,
74
74
  version: "0.7"
75
75
  }
76
76
  ],
@@ -102,20 +102,17 @@ const OgChainConfig: ChainWalletConfig = {
102
102
  const wallet = new EVMChainWallet(evmChainConfig, evmPrivateKeyExposed, 0)
103
103
 
104
104
  //IIFE
105
- const walletA = new EVMChainWallet(evmChainConfig, evmPrivateKeyExposed, 0); //wallet that usdc to send
105
+ const walletA = new EVMChainWallet(evmChainConfig, evmPrivateKeyExposed, 0); //wallet that has usdc to send
106
106
  const walletB = new EVMChainWallet(evmChainConfig, evmPrivKey, 0); // wallet that has gas
107
107
  const SEPOLIA_USDC_ADDRESS = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' as Hex;
108
108
  const BASE_USDC_ADDRESS = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913' as Hex;
109
109
  const bundlerUrl = `https://api.pimlico.io/v2/${evmChainConfig.chainId}/rpc?apikey=pim_3UEhbTpS98H1XFm8p9kRxg`;
110
110
 
111
111
  const RECIPIENT = "0x7027F9C9a701adCbfCD55D16aD219501D4b9589A";
112
- (async () => {
113
- return
114
- console.log("walletA address: ", walletA.address);
115
- console.log("walletB address: ", walletB.address);
112
+ const testSessionKeys = async () => {
116
113
 
114
+ console.log("walletA address: ", walletA.address);
117
115
 
118
- //GET TOKEN LOGO using @solana/spl-token-metadata
119
116
  const walletANativeBalance = await walletA.getNativeBalance();
120
117
  console.log('walletA native balance: ', walletANativeBalance);
121
118
 
@@ -125,6 +122,9 @@ const RECIPIENT = "0x7027F9C9a701adCbfCD55D16aD219501D4b9589A";
125
122
  //wallet B USDC balance
126
123
  const walletBUSDCBalance = await walletB.getTokenBalance(BASE_USDC_ADDRESS);
127
124
  console.log('walletB USDC balance: ', walletBUSDCBalance);
125
+ console.log("walletB address: ", walletB.address);
126
+
127
+
128
128
 
129
129
  //extend wallet A wallet to a smart wallet with AA support
130
130
  const extendedWalletA = await walletA.extend({
@@ -134,17 +134,82 @@ const RECIPIENT = "0x7027F9C9a701adCbfCD55D16aD219501D4b9589A";
134
134
  // console.log('extendedWalletA: ', extendedWalletA);
135
135
  const initializedExtendedWalletA = await extendedWalletA.initialize()
136
136
 
137
- // console.log('initializedExtendedWalletA: ', initializedExtendedWalletA);
137
+
138
+ //now we want to test session keys
139
+ const sessionKeys = await initializedExtendedWalletA.generateSessionKey()
140
+ console.log('sessionKeys: ', sessionKeys);
141
+
142
+
138
143
 
139
144
 
145
+ // return;
146
+ const usdcPermission = initializedExtendedWalletA.createUSDCPermission(
147
+ BASE_USDC_ADDRESS,
148
+ "1", // approve up to 100 USDC,
149
+ RECIPIENT
150
+ )
151
+ console.log('usdcPermission: ', usdcPermission);
152
+ const sessionKeyApproval = await initializedExtendedWalletA.approveSessionKey(
153
+ {
154
+ sessionKeyAddress: sessionKeys.address,
155
+ sessionKeyPrivateKey: sessionKeys.privateKey,
156
+ permissions: [usdcPermission],
157
+ // useSudoPolicy: true,
158
+ }
159
+ )
140
160
 
141
- })();
161
+ const data = encodeFunctionData({
162
+ abi: parseAbi([
163
+ 'function transfer(address to, uint256 amount) public returns (bool)'
164
+ ]),
165
+ functionName: 'transfer',
166
+ args: [RECIPIENT, parseUnits('0.01', 6)]
167
+ }) // transfer 10 USDC
168
+ console.log('sessionKeyApproval: ', sessionKeyApproval);
169
+
170
+
171
+
172
+ const sessionKeyAccount = await deserializeSessionKey({
173
+ approval: sessionKeyApproval,
174
+ sessionKeySigner: sessionKeys.signer,
175
+ chain: base
176
+ })
177
+
178
+ //send transaction using session key
179
+
180
+ const sessionAccount = {
181
+ account: sessionKeyAccount,
182
+ address: sessionKeyAccount.address,
183
+ };
184
+
185
+ const hash = await initializedExtendedWalletA.sendTransaction(BASE_USDC_ADDRESS, 0n, data, {
186
+ sessionAccount: sessionAccount
187
+ })
188
+ console.log('hash: ', hash);
189
+ //get session key client
190
+
191
+
192
+
193
+
194
+ }
195
+
196
+ const testModule = async () => {
197
+ const extendedWalletA = await walletA.extend({
198
+ bundlerUrl: bundlerUrl
199
+ })
200
+
201
+ const initializedExtendedWalletA = await extendedWalletA.initialize()
202
+
203
+
204
+
205
+ //this is where we will test installation of modules
206
+ }
142
207
 
143
208
 
144
209
 
145
210
  // console.log('wallet: ', wallet);
146
211
  // getTokenInfo(new PublicKey("9BB6NFEcjBCtnNLFko2FqVQBq8HHM13kCyYcdQbgpump"), wallet.connection!).then(e => console.log('token info: ', e))
147
- wallet.discoverToken().then(e => console.log('discovered tokens: ', e))
212
+
148
213
  // wallet.getNativeBalance().then(e => console.log('native balance: ', e))
149
214
 
150
215
  // const toBuy = new PublicKey("9BB6NFEcjBCtnNLFko2FqVQBq8HHM13kCyYcdQbgpump")
package/utils/vm.ts CHANGED
@@ -1,7 +1,8 @@
1
-
2
1
  import { Balance, ChainWalletConfig, TokenInfo, vmTypes } from "./types";
3
2
  import * as bip39 from "@scure/bip39";
4
3
  import CryptoJS from "crypto-js";
4
+ import { PriceResponse } from "./price.types";
5
+
5
6
  // Abstract Base Classes
6
7
  export abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
7
8
  protected seed: string;
@@ -70,6 +71,16 @@ export abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
70
71
  abstract generatePrivateKey(index: number, mnemonic?: string, derivationPath?: string): { privateKey: PrivateKeyType, index: number };
71
72
  abstract getTokenInfo(tokenAddress: AddressType, connection: ConnectionType): Promise<TokenInfo>
72
73
 
74
+ /**
75
+ * Derive a savings account using BIP-44 account index
76
+ *
77
+ * Main wallet uses: m/44'/60'/0'/0/0 (account index 0)
78
+ * Savings accounts use: m/44'/60'/N'/0/0 (account index N)
79
+ *
80
+ * @param accountIndex - The BIP-44 account index (1 for first savings, 2 for second, etc.)
81
+ * @returns Object containing privateKey, address, and derivation path
82
+ */
83
+ abstract deriveSavingsAccount(accountIndex: number): { privateKey: PrivateKeyType; address: AddressType; derivationPath: string };
73
84
 
74
85
  // abstract validateAddress(address: AddressType): boolean;
75
86
  // abstract getNativeBalance(address: AddressType, connection: ConnectionType): Promise<Balance>;