@deserialize/multi-vm-wallet 1.5.21 → 1.5.31

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/dist/svm/svm.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SVMChainWallet = exports.SVMVM = void 0;
6
+ exports.SVMChainWallet = exports.SVMChainAddress = exports.SVMVM = exports.getSvmPricesForTokens = exports.getSvmTransactionHistoryForAddress = exports.discoverSvmNFTs = exports.discoverSvmTokens = exports.getSvmTokenBalanceForAddress = exports.getSvmNativeBalanceForAddress = exports.createSvmConnection = void 0;
7
7
  const web3_js_1 = require("@solana/web3.js");
8
8
  const walletBip32_1 = require("../walletBip32");
9
9
  const vm_1 = require("../vm");
@@ -15,6 +15,40 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
15
15
  const bs58_1 = __importDefault(require("bs58"));
16
16
  const price_1 = require("../price");
17
17
  const transactionParsing_1 = require("./transactionParsing");
18
+ const createSvmConnection = (config) => new web3_js_1.Connection(config.rpcUrl);
19
+ exports.createSvmConnection = createSvmConnection;
20
+ const getSvmNativeBalanceForAddress = async (address, connection) => {
21
+ return await SVMVM.getNativeBalance(address, connection);
22
+ };
23
+ exports.getSvmNativeBalanceForAddress = getSvmNativeBalanceForAddress;
24
+ const getSvmTokenBalanceForAddress = async (address, tokenAddress, connection) => {
25
+ return await SVMVM.getTokenBalance(address, tokenAddress, connection);
26
+ };
27
+ exports.getSvmTokenBalanceForAddress = getSvmTokenBalanceForAddress;
28
+ const discoverSvmTokens = async (address, connection) => {
29
+ return await (0, utils_1.discoverTokens)(address, connection);
30
+ };
31
+ exports.discoverSvmTokens = discoverSvmTokens;
32
+ const discoverSvmNFTs = async (address, connection) => {
33
+ return await (0, utils_1.fetchWalletNfts)(address, connection);
34
+ };
35
+ exports.discoverSvmNFTs = discoverSvmNFTs;
36
+ const getSvmTransactionHistoryForAddress = async (connection, address) => {
37
+ return await (0, transactionParsing_1.getSVMTransactionHistory)(connection, address);
38
+ };
39
+ exports.getSvmTransactionHistoryForAddress = getSvmTransactionHistoryForAddress;
40
+ const getSvmPricesForTokens = async (config, tokenAddresses) => {
41
+ const result = await (0, price_1.fetchPrices)({
42
+ vm: 'SVM',
43
+ chainId: config.chainId,
44
+ tokenAddresses,
45
+ });
46
+ if (result.error) {
47
+ throw new Error(result.error.message);
48
+ }
49
+ return result.data;
50
+ };
51
+ exports.getSvmPricesForTokens = getSvmPricesForTokens;
18
52
  class SVMVM extends vm_1.VM {
19
53
  getTokenInfo = utils_1.getTokenInfo;
20
54
  static getTokenInfo = utils_1.getTokenInfo;
@@ -27,7 +61,7 @@ class SVMVM extends vm_1.VM {
27
61
  return false;
28
62
  }
29
63
  }
30
- derivationPath = "m/44'/501'/";
64
+ derivationPath = "m/44'/501'/0'/";
31
65
  constructor(seed) {
32
66
  super(seed, "SVM");
33
67
  }
@@ -330,12 +364,39 @@ class SVMVM extends vm_1.VM {
330
364
  }
331
365
  }
332
366
  exports.SVMVM = SVMVM;
367
+ class SVMChainAddress extends IChainWallet_1.ChainAddress {
368
+ constructor(config, address, index) {
369
+ const connection = (0, exports.createSvmConnection)(config);
370
+ super(config, address, index);
371
+ this.connection = connection;
372
+ }
373
+ async getNativeBalance() {
374
+ return await (0, exports.getSvmNativeBalanceForAddress)(this.address, this.connection);
375
+ }
376
+ async getTokenBalance(tokenAddress) {
377
+ return await (0, exports.getSvmTokenBalanceForAddress)(this.address, tokenAddress, this.connection);
378
+ }
379
+ async discoverToken() {
380
+ return await (0, exports.discoverSvmTokens)(this.address, this.connection);
381
+ }
382
+ async discoverNFT() {
383
+ return await (0, exports.discoverSvmNFTs)(this.address, this.connection);
384
+ }
385
+ async getTransactionHistory() {
386
+ return await (0, exports.getSvmTransactionHistoryForAddress)(this.connection, this.address);
387
+ }
388
+ async getPrices(tokenAddresses) {
389
+ return await (0, exports.getSvmPricesForTokens)(this.config, tokenAddresses);
390
+ }
391
+ }
392
+ exports.SVMChainAddress = SVMChainAddress;
333
393
  class SVMChainWallet extends IChainWallet_1.ChainWallet {
334
394
  constructor(config, privateKey, index) {
335
- super(config, privateKey, index);
395
+ const address = privateKey.publicKey;
396
+ super(config, address, privateKey, index);
336
397
  this.address = privateKey.publicKey;
337
398
  this.privateKey = privateKey;
338
- this.connection = new web3_js_1.Connection(config.rpcUrl);
399
+ this.connection = (0, exports.createSvmConnection)(config);
339
400
  }
340
401
  generateAddress() {
341
402
  return this.address;
@@ -344,18 +405,16 @@ class SVMChainWallet extends IChainWallet_1.ChainWallet {
344
405
  return web3_js_1.Keypair.fromSeed(Buffer.from(entropy));
345
406
  };
346
407
  async getNativeBalance() {
347
- return await SVMVM.getNativeBalance(this.address, this.connection);
408
+ return await (0, exports.getSvmNativeBalanceForAddress)(this.address, this.connection);
348
409
  }
349
410
  async getTokenBalance(tokenAddress) {
350
- return await SVMVM.getTokenBalance(this.address, (tokenAddress), this.connection);
411
+ return await (0, exports.getSvmTokenBalanceForAddress)(this.address, tokenAddress, this.connection);
351
412
  }
352
413
  async discoverToken() {
353
- const tokens = await (0, utils_1.discoverTokens)(this.address, this.connection);
354
- return tokens;
414
+ return await (0, exports.discoverSvmTokens)(this.address, this.connection);
355
415
  }
356
416
  async discoverNFT() {
357
- const nfts = await (0, utils_1.fetchWalletNfts)(this.address, this.connection);
358
- return nfts;
417
+ return await (0, exports.discoverSvmNFTs)(this.address, this.connection);
359
418
  }
360
419
  async transferNative(to, amount) {
361
420
  const transaction = await (0, utils_1.getTransferNativeTransaction)(this.privateKey, to, amount, this.connection);
@@ -377,22 +436,13 @@ class SVMChainWallet extends IChainWallet_1.ChainWallet {
377
436
  return await SVMVM.signAndSendTransaction(transaction, this.connection, this.privateKey);
378
437
  }
379
438
  async getTransactionHistory() {
380
- const history = await (0, transactionParsing_1.getSVMTransactionHistory)(this.connection, this.address);
381
- return history;
439
+ return await (0, exports.getSvmTransactionHistoryForAddress)(this.connection, this.address);
382
440
  }
383
441
  async getTokenInfo(tokenAddress) {
384
442
  return await SVMVM.getTokenInfo(tokenAddress, this.connection);
385
443
  }
386
444
  async getPrices(tokenAddresses) {
387
- const result = await (0, price_1.fetchPrices)({
388
- vm: 'SVM',
389
- chainId: this.config.chainId,
390
- tokenAddresses,
391
- });
392
- if (result.error) {
393
- throw new Error(result.error.message);
394
- }
395
- return result.data;
445
+ return await (0, exports.getSvmPricesForTokens)(this.config, tokenAddresses);
396
446
  }
397
447
  async swap(fromToken, toToken, amount, slippage = 50) {
398
448
  try {
package/dist/test.js CHANGED
@@ -233,5 +233,17 @@ const testSavingsPocketMultiChain = async () => {
233
233
  multiChainManager.dispose();
234
234
  console.log('\n✅ Multi-Chain Savings Test Complete\n');
235
235
  };
236
+ const testEntropy = () => {
237
+ const p = evm_1.EVMVM.convertFromEntropyToPrivateKey("thishgbmytesentropystringis32bytes!hjkjkhknkjtdyftgkh,jryctdrfygh");
238
+ console.log('p: ', p);
239
+ const res = new evm_1.EVMChainWallet(evmChainConfig, p, 0);
240
+ console.log('res: ', res);
241
+ };
242
+ const testAddressClass = async () => {
243
+ const evmAddressClass = new evm_1.EVMChainAddress(evmChainConfig, "0xC9C1D854b82BA9b4FB6f6D58E9EF3d1fAEd601AA", 0);
244
+ const res = await evmAddressClass.getNativeBalance();
245
+ console.log('res: ', res);
246
+ };
247
+ testAddressClass();
236
248
  const RPC_URL = chainConfig.rpcUrl;
237
249
  const connection = new web3_js_1.Connection(RPC_URL);
package/dist/types.d.ts CHANGED
@@ -16,8 +16,12 @@ export interface ChainWalletConfig {
16
16
  confirmationNo?: number;
17
17
  testnet?: boolean;
18
18
  vmType: vmTypes;
19
+ savings?: ChainSavingConfig;
19
20
  aaSupport?: AA_SupportConfig;
20
21
  }
22
+ export interface ChainSavingConfig {
23
+ tokens: string[];
24
+ }
21
25
  export interface AA_SupportConfig {
22
26
  enabled: boolean;
23
27
  entryPoints: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deserialize/multi-vm-wallet",
3
- "version": "1.5.21",
3
+ "version": "1.5.31",
4
4
  "devDependencies": {
5
5
  "@types/bn.js": "^5.2.0",
6
6
  "@types/crypto-js": "^4.2.2",
@@ -3,36 +3,26 @@ import { PriceResponse } from "./price.types";
3
3
  import { SVMTransactionHistoryItem } from "./svm/transactionParsing";
4
4
  import { Balance, ChainWalletConfig, NFTInfo, TokenInfo, TransactionResult, UserTokenBalance, NFT } from "./types";
5
5
 
6
- export abstract class ChainWallet<AddressType, PrivateKeyType, ConnectionType> {
7
- protected privateKey: PrivateKeyType;
6
+ export abstract class ChainAddress<AddressType, ConnectionType> {
7
+
8
8
  config: ChainWalletConfig;
9
9
  address: AddressType;
10
10
  index: number | undefined
11
11
  connection: ConnectionType | undefined
12
12
 
13
- constructor(config: ChainWalletConfig, privateKey: PrivateKeyType, index?: number) {
13
+ constructor(config: ChainWalletConfig, address: AddressType, index?: number) {
14
14
  this.config = config;
15
- this.privateKey = privateKey;
16
- this.address = this.generateAddress(privateKey);
15
+ this.address = address;
17
16
  this.index = index;
18
17
 
19
18
  }
20
19
 
21
- abstract generateAddress(privateKey: PrivateKeyType): AddressType;
22
20
  abstract getNativeBalance(): Promise<Balance>;
23
21
  abstract getTokenBalance(tokenAddress: AddressType): Promise<Balance>;
24
- abstract transferNative(to: AddressType, amount: number): Promise<TransactionResult>;
25
- abstract transferToken(tokenAddress: TokenInfo, to: AddressType, amount: number): Promise<TransactionResult>;
26
- abstract swap(tokenAddress: TokenInfo, to: AddressType, amount: number, slippage?: number): Promise<TransactionResult>;
27
22
  abstract discoverToken(): Promise<UserTokenBalance<AddressType>[]>;
28
23
  abstract discoverNFT(): Promise<NFT[]>;
29
24
  abstract getTransactionHistory(): Promise<(SVMTransactionHistoryItem | EVMTransactionHistoryItem)[]>;
30
25
  abstract getPrices(tokenAddresses: string[]): Promise<PriceResponse>
31
- // abstract transferNFT(contractAddress: AddressType, tokenId: string, to: string): Promise<TransactionResult>;
32
- // abstract getTokenInfo(tokenAddress: string): Promise<TokenInfo>;
33
- // abstract getNFTInfo(contractAddress: string, tokenId: string): Promise<NFTInfo>;
34
- // abstract getTransactionHistory(): Promise<any[]>;
35
-
36
26
  getAddress(): AddressType {
37
27
  return this.address;
38
28
  }
@@ -42,6 +32,77 @@ export abstract class ChainWallet<AddressType, PrivateKeyType, ConnectionType> {
42
32
 
43
33
 
44
34
 
45
- abstract convertFromEntropyToPrivateKey(entropy: string): PrivateKeyType
46
35
 
36
+
37
+ }
38
+
39
+ export abstract class ChainWallet<
40
+ AddressType,
41
+ PrivateKeyType,
42
+ ConnectionType
43
+ > extends ChainAddress<AddressType, ConnectionType> {
44
+
45
+ protected privateKey: PrivateKeyType;
46
+
47
+ /**
48
+ * Protected constructor so wallets are created through factories
49
+ */
50
+ constructor(
51
+ config: ChainWalletConfig,
52
+ address: AddressType,
53
+ privateKey: PrivateKeyType,
54
+ index?: number
55
+ ) {
56
+ super(config, address, index);
57
+
58
+ this.privateKey = privateKey;
59
+ }
60
+
61
+ /**
62
+ * Each chain must implement how an address is derived
63
+ */
64
+ protected abstract generateAddress(
65
+ privateKey: PrivateKeyType
66
+ ): AddressType;
67
+
68
+ /**
69
+ * Transfer native coin (ETH, SOL, etc.)
70
+ */
71
+ abstract transferNative(
72
+ to: AddressType,
73
+ amount: number
74
+ ): Promise<TransactionResult>;
75
+
76
+ /**
77
+ * Transfer ERC20 / SPL token
78
+ */
79
+ abstract transferToken(
80
+ tokenAddress: TokenInfo,
81
+ to: AddressType,
82
+ amount: number
83
+ ): Promise<TransactionResult>;
84
+
85
+ /**
86
+ * Swap tokens
87
+ */
88
+ abstract swap(
89
+ tokenAddress: TokenInfo,
90
+ to: AddressType,
91
+ amount: number,
92
+ slippage?: number
93
+ ): Promise<TransactionResult>;
94
+
95
+ /**
96
+ * Convert entropy/mnemonic → private key
97
+ */
98
+ abstract convertFromEntropyToPrivateKey(
99
+ entropy: string
100
+ ): PrivateKeyType;
101
+
102
+ /**
103
+ * Expose private key only internally if needed
104
+ */
105
+ protected getPrivateKey(): PrivateKeyType {
106
+ return this.privateKey;
107
+ }
47
108
  }
package/utils/constant.ts CHANGED
@@ -1,35 +1,7 @@
1
- import { base } from "viem/chains";
1
+ import { arbitrum, base, optimism } from "viem/chains";
2
2
  import { ChainWalletConfig } from "./types";
3
3
 
4
4
  export const DefaultChains: ChainWalletConfig[] = [{
5
-
6
- chainId: 24101,
7
- name: "Incentiv",
8
- rpcUrl: "https://rpc.incentiv.io",
9
- explorerUrl: "https://explorer.incentiv.io",
10
- nativeToken: {
11
- name: "Incentiv",
12
- symbol: "CENT",
13
- decimals: 18,
14
- },
15
- testnet: false,
16
- logoUrl: "https://incentiv.io/wp-content/uploads/2024/09/cropped-Favicon-1-32x32.png",
17
- vmType: "EVM"
18
- }, {
19
-
20
- chainId: 16661,
21
- name: "0G",
22
- rpcUrl: "https://evmrpc.0g.ai",
23
- explorerUrl: "https://chainscan.0g.ai/",
24
- nativeToken: {
25
- name: "OG Mainnet",
26
- symbol: "0G",
27
- decimals: 18,
28
- },
29
- testnet: false,
30
- logoUrl: "https://chainscan.0g.ai/static/media/zg-logo-new.b22d59dabf457524325ca81c29a4e055.svg",
31
- vmType: "EVM"
32
- }, {
33
5
  chainId: 123456789,
34
6
  name: "Solana",
35
7
  rpcUrl: "https://solana-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
@@ -41,7 +13,10 @@ export const DefaultChains: ChainWalletConfig[] = [{
41
13
  },
42
14
  testnet: false,
43
15
  logoUrl: "https://solana.com/src/img/branding/solanaLogoMark.svg",
44
- vmType: "SVM"
16
+ vmType: "SVM",
17
+ savings: {
18
+ tokens: []
19
+ }
45
20
  }
46
21
  , {
47
22
  chainId: 1,
@@ -68,7 +43,10 @@ export const DefaultChains: ChainWalletConfig[] = [{
68
43
  },
69
44
  testnet: false,
70
45
  logoUrl: "https://bscscan.com/assets/bsc/images/svg/logos/token-light.svg?v=25.10.5.0",
71
- vmType: "EVM"
46
+ vmType: "EVM",
47
+ savings: {
48
+ tokens: []
49
+ }
72
50
  },
73
51
 
74
52
  // {
@@ -98,36 +76,45 @@ export const DefaultChains: ChainWalletConfig[] = [{
98
76
  },
99
77
  testnet: base.testnet,
100
78
  logoUrl: "https://avatars.githubusercontent.com/u/108554348?s=200&v=4",
101
- vmType: "EVM"
79
+ vmType: "EVM",
80
+ savings: {
81
+ tokens: []
82
+ }
102
83
  },
103
84
 
104
85
  {
105
- chainId: 42161,
106
- name: "Arbitrum One",
107
- rpcUrl: "https://arbitrum-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
108
- explorerUrl: "https://arbiscan.io",
86
+ chainId: arbitrum.id,
87
+ name: arbitrum.name,
88
+ rpcUrl: arbitrum.rpcUrls.default.http[0],
89
+ explorerUrl: arbitrum.blockExplorers?.default.url,
109
90
  nativeToken: {
110
- name: "Ether",
111
- symbol: "ETH",
112
- decimals: 18,
91
+ name: arbitrum.nativeCurrency.name,
92
+ symbol: arbitrum.nativeCurrency.symbol,
93
+ decimals: arbitrum.nativeCurrency.decimals,
113
94
  },
114
95
  testnet: false,
115
- logoUrl: "https://arbiscan.io/images/svg/brands/arbitrum-light.svg?v=0.0.36",
116
- vmType: "EVM"
96
+ logoUrl: "https://avatars.githubusercontent.com/u/119917794?s=280&v=4",
97
+ vmType: "EVM",
98
+ savings: {
99
+ tokens: []
100
+ }
117
101
  },
118
102
  {
119
- chainId: 10,
120
- name: "Optimism",
121
- rpcUrl: "https://optimism-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
122
- explorerUrl: "https://optimistic.etherscan.io",
103
+ chainId: optimism.id,
104
+ name: optimism.name,
105
+ rpcUrl: optimism.rpcUrls.default.http[0],
106
+ explorerUrl: optimism.blockExplorers?.default.url,
123
107
  nativeToken: {
124
- name: "Ether",
125
- symbol: "ETH",
126
- decimals: 18,
108
+ name: optimism.nativeCurrency.name,
109
+ symbol: optimism.nativeCurrency.symbol,
110
+ decimals: optimism.nativeCurrency.decimals,
127
111
  },
128
112
  testnet: false,
129
- logoUrl: "https://optimism.io/images/optimism-logo-light.svg",
130
- vmType: "EVM"
113
+ logoUrl: "https://avatars.githubusercontent.com/u/58791460?s=280&v=4",
114
+ vmType: "EVM",
115
+ savings: {
116
+ tokens: []
117
+ }
131
118
  },
132
119
 
133
120
  //add for polygon
@@ -143,7 +130,10 @@ export const DefaultChains: ChainWalletConfig[] = [{
143
130
  },
144
131
  testnet: false,
145
132
  logoUrl: "https://polygonscan.com/images/svg/brands/polygon-light.svg?v=0.0.36",
146
- vmType: "EVM"
133
+ vmType: "EVM",
134
+ savings: {
135
+ tokens: []
136
+ }
147
137
  }
148
138
 
149
139