@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.
- package/.claude/settings.local.json +2 -1
- package/dist/IChainWallet.d.ts +2 -0
- package/dist/IChainWallet.js.map +1 -1
- package/dist/constant.js +60 -16
- package/dist/constant.js.map +1 -1
- package/dist/evm/aa-service/index.d.ts +1 -1
- package/dist/evm/aa-service/index.js +1 -2
- package/dist/evm/aa-service/index.js.map +1 -1
- package/dist/evm/aa-service/lib/kernel-account.d.ts +1 -1
- package/dist/evm/aa-service/lib/kernel-account.js +22 -6
- package/dist/evm/aa-service/lib/kernel-account.js.map +1 -1
- package/dist/evm/aa-service/lib/session-keys.d.ts +14 -17
- package/dist/evm/aa-service/lib/session-keys.js +40 -58
- package/dist/evm/aa-service/lib/session-keys.js.map +1 -1
- package/dist/evm/aa-service/lib/type.d.ts +2 -1
- package/dist/evm/aa-service/lib/type.js.map +1 -1
- package/dist/evm/aa-service/services/account-abstraction.d.ts +3 -29
- package/dist/evm/aa-service/services/account-abstraction.js +3 -67
- package/dist/evm/aa-service/services/account-abstraction.js.map +1 -1
- package/dist/evm/aa-service/services/bundler.js +2 -1
- package/dist/evm/aa-service/services/bundler.js.map +1 -1
- package/dist/evm/evm.d.ts +163 -1
- package/dist/evm/evm.js +259 -0
- package/dist/evm/evm.js.map +1 -1
- package/dist/evm/smartWallet.d.ts +11 -43
- package/dist/evm/smartWallet.js +136 -116
- package/dist/evm/smartWallet.js.map +1 -1
- package/dist/evm/utils.js +0 -1
- package/dist/evm/utils.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/price.d.ts +2 -0
- package/dist/price.js +33 -0
- package/dist/price.js.map +1 -0
- package/dist/price.types.d.ts +38 -0
- package/dist/price.types.js +4 -0
- package/dist/price.types.js.map +1 -0
- package/dist/privacy/artifact-manager.d.ts +117 -0
- package/dist/privacy/artifact-manager.js +251 -0
- package/dist/privacy/artifact-manager.js.map +1 -0
- package/dist/privacy/broadcaster-client.d.ts +166 -0
- package/dist/privacy/broadcaster-client.js +261 -0
- package/dist/privacy/broadcaster-client.js.map +1 -0
- package/dist/privacy/index.d.ts +34 -0
- package/dist/privacy/index.js +56 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/privacy/network-config.d.ts +57 -0
- package/dist/privacy/network-config.js +118 -0
- package/dist/privacy/network-config.js.map +1 -0
- package/dist/privacy/poi-helper.d.ts +161 -0
- package/dist/privacy/poi-helper.js +249 -0
- package/dist/privacy/poi-helper.js.map +1 -0
- package/dist/privacy/railgun-engine.d.ts +135 -0
- package/dist/privacy/railgun-engine.js +205 -0
- package/dist/privacy/railgun-engine.js.map +1 -0
- package/dist/privacy/railgun-privacy-wallet.d.ts +288 -0
- package/dist/privacy/railgun-privacy-wallet.js +539 -0
- package/dist/privacy/railgun-privacy-wallet.js.map +1 -0
- package/dist/privacy/types.d.ts +229 -0
- package/dist/privacy/types.js +26 -0
- package/dist/privacy/types.js.map +1 -0
- package/dist/savings/savings-manager.d.ts +126 -0
- package/dist/savings/savings-manager.js +234 -0
- package/dist/savings/savings-manager.js.map +1 -0
- package/dist/savings/smart-savings.d.ts +74 -0
- package/dist/savings/smart-savings.js +152 -0
- package/dist/savings/smart-savings.js.map +1 -0
- package/dist/savings/types.d.ts +125 -0
- package/dist/savings/types.js +9 -0
- package/dist/savings/types.js.map +1 -0
- package/dist/svm/svm.d.ts +18 -0
- package/dist/svm/svm.js +35 -0
- package/dist/svm/svm.js.map +1 -1
- package/dist/test.js +53 -15
- package/dist/test.js.map +1 -1
- package/dist/vm.d.ts +14 -0
- package/dist/vm.js.map +1 -1
- package/package.json +2 -1
- package/utils/IChainWallet.ts +2 -0
- package/utils/constant.ts +63 -16
- package/utils/evm/aa-service/index.ts +0 -1
- package/utils/evm/aa-service/lib/kernel-account.ts +23 -8
- package/utils/evm/aa-service/lib/session-keys.ts +58 -60
- package/utils/evm/aa-service/lib/type.ts +2 -1
- package/utils/evm/aa-service/services/account-abstraction.ts +10 -76
- package/utils/evm/aa-service/services/bundler.ts +2 -1
- package/utils/evm/evm.ts +317 -0
- package/utils/evm/smartWallet.ts +118 -128
- package/utils/evm/utils.ts +1 -1
- package/utils/index.ts +1 -0
- package/utils/price.ts +37 -0
- package/utils/price.types.ts +45 -0
- package/utils/savings/savings-manager.ts +271 -0
- package/utils/savings/smart-savings.ts +184 -0
- package/utils/savings/types.ts +135 -0
- package/utils/svm/svm.ts +43 -2
- package/utils/test.ts +84 -19
- 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 = "
|
|
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 = "
|
|
38
|
-
const evmPrivateKeyExposed = "
|
|
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://
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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>;
|