@deserialize/multi-vm-wallet 1.5.2 → 1.5.3
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/IChainWallet.d.ts +11 -7
- package/dist/IChainWallet.js +15 -6
- package/dist/evm/evm.d.ts +10 -1
- package/dist/evm/evm.js +82 -32
- package/dist/evm/utils.d.ts +1 -0
- package/dist/evm/utils.js +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/svm/svm.d.ts +10 -1
- package/dist/svm/svm.js +64 -21
- package/dist/test.js +7 -0
- package/package.json +1 -1
- package/utils/IChainWallet.ts +76 -15
- package/utils/evm/evm.ts +123 -291
- package/utils/evm/utils.ts +12 -0
- package/utils/index.ts +2 -2
- package/utils/savings/svm-savings.ts +1 -1
- package/utils/svm/svm.ts +100 -24
- package/utils/test.ts +9 -0
- package/utils/utils.ts +7 -0
package/dist/IChainWallet.d.ts
CHANGED
|
@@ -2,24 +2,28 @@ import { EVMTransactionHistoryItem } from "./evm/transactionParsing";
|
|
|
2
2
|
import { PriceResponse } from "./price.types";
|
|
3
3
|
import { SVMTransactionHistoryItem } from "./svm/transactionParsing";
|
|
4
4
|
import { Balance, ChainWalletConfig, TokenInfo, TransactionResult, UserTokenBalance, NFT } from "./types";
|
|
5
|
-
export declare abstract class
|
|
6
|
-
protected privateKey: PrivateKeyType;
|
|
5
|
+
export declare abstract class ChainAddress<AddressType, ConnectionType> {
|
|
7
6
|
config: ChainWalletConfig;
|
|
8
7
|
address: AddressType;
|
|
9
8
|
index: number | undefined;
|
|
10
9
|
connection: ConnectionType | undefined;
|
|
11
|
-
constructor(config: ChainWalletConfig,
|
|
12
|
-
abstract generateAddress(privateKey: PrivateKeyType): AddressType;
|
|
10
|
+
constructor(config: ChainWalletConfig, address: AddressType, index?: number);
|
|
13
11
|
abstract getNativeBalance(): Promise<Balance>;
|
|
14
12
|
abstract getTokenBalance(tokenAddress: AddressType): Promise<Balance>;
|
|
15
|
-
abstract transferNative(to: AddressType, amount: number): Promise<TransactionResult>;
|
|
16
|
-
abstract transferToken(tokenAddress: TokenInfo, to: AddressType, amount: number): Promise<TransactionResult>;
|
|
17
|
-
abstract swap(tokenAddress: TokenInfo, to: AddressType, amount: number, slippage?: number): Promise<TransactionResult>;
|
|
18
13
|
abstract discoverToken(): Promise<UserTokenBalance<AddressType>[]>;
|
|
19
14
|
abstract discoverNFT(): Promise<NFT[]>;
|
|
20
15
|
abstract getTransactionHistory(): Promise<(SVMTransactionHistoryItem | EVMTransactionHistoryItem)[]>;
|
|
21
16
|
abstract getPrices(tokenAddresses: string[]): Promise<PriceResponse>;
|
|
22
17
|
getAddress(): AddressType;
|
|
23
18
|
getChainWalletConfig(): ChainWalletConfig;
|
|
19
|
+
}
|
|
20
|
+
export declare abstract class ChainWallet<AddressType, PrivateKeyType, ConnectionType> extends ChainAddress<AddressType, ConnectionType> {
|
|
21
|
+
protected privateKey: PrivateKeyType;
|
|
22
|
+
constructor(config: ChainWalletConfig, address: AddressType, privateKey: PrivateKeyType, index?: number);
|
|
23
|
+
protected abstract generateAddress(privateKey: PrivateKeyType): AddressType;
|
|
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>;
|
|
24
27
|
abstract convertFromEntropyToPrivateKey(entropy: string): PrivateKeyType;
|
|
28
|
+
protected getPrivateKey(): PrivateKeyType;
|
|
25
29
|
}
|
package/dist/IChainWallet.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChainWallet = void 0;
|
|
4
|
-
class
|
|
5
|
-
privateKey;
|
|
3
|
+
exports.ChainWallet = exports.ChainAddress = void 0;
|
|
4
|
+
class ChainAddress {
|
|
6
5
|
config;
|
|
7
6
|
address;
|
|
8
7
|
index;
|
|
9
8
|
connection;
|
|
10
|
-
constructor(config,
|
|
9
|
+
constructor(config, address, index) {
|
|
11
10
|
this.config = config;
|
|
12
|
-
this.
|
|
13
|
-
this.address = this.generateAddress(privateKey);
|
|
11
|
+
this.address = address;
|
|
14
12
|
this.index = index;
|
|
15
13
|
}
|
|
16
14
|
getAddress() {
|
|
@@ -20,4 +18,15 @@ class ChainWallet {
|
|
|
20
18
|
return this.config;
|
|
21
19
|
}
|
|
22
20
|
}
|
|
21
|
+
exports.ChainAddress = ChainAddress;
|
|
22
|
+
class ChainWallet extends ChainAddress {
|
|
23
|
+
privateKey;
|
|
24
|
+
constructor(config, address, privateKey, index) {
|
|
25
|
+
super(config, address, index);
|
|
26
|
+
this.privateKey = privateKey;
|
|
27
|
+
}
|
|
28
|
+
getPrivateKey() {
|
|
29
|
+
return this.privateKey;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
23
32
|
exports.ChainWallet = ChainWallet;
|
package/dist/evm/evm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainWallet } from "../IChainWallet";
|
|
1
|
+
import { ChainAddress, ChainWallet } from "../IChainWallet";
|
|
2
2
|
import { Balance, ChainWalletConfig, UserTokenBalance, TokenInfo, TransactionResult, NFT, WalletDiscoveryOptions, WalletDiscoveryResult, PocketDiscoveryOptions } from "../types";
|
|
3
3
|
import { VM } from "../vm";
|
|
4
4
|
import { JsonRpcProvider } from "ethers";
|
|
@@ -29,6 +29,15 @@ export declare class EVMVM extends VM<string, string, PublicClient> {
|
|
|
29
29
|
discoverPockets(connection: JsonRpcProvider | PublicClient, options?: PocketDiscoveryOptions): Promise<WalletDiscoveryResult>;
|
|
30
30
|
private checkPocketBalance;
|
|
31
31
|
}
|
|
32
|
+
export declare class EVMChainAddress extends ChainAddress<string, PublicClient> {
|
|
33
|
+
constructor(config: ChainWalletConfig, address: string, index?: number);
|
|
34
|
+
getNativeBalance(): Promise<Balance>;
|
|
35
|
+
getTokenBalance(tokenAddress: string): Promise<Balance>;
|
|
36
|
+
discoverToken(): Promise<UserTokenBalance<string>[]>;
|
|
37
|
+
discoverNFT(): Promise<NFT[]>;
|
|
38
|
+
getTransactionHistory(): Promise<EVMTransactionHistoryItem[]>;
|
|
39
|
+
getPrices(tokenAddresses: string[]): Promise<PriceResponse>;
|
|
40
|
+
}
|
|
32
41
|
export declare class EVMChainWallet extends ChainWallet<string, string, PublicClient> {
|
|
33
42
|
wallet: WalletClient;
|
|
34
43
|
private smartWallet?;
|
package/dist/evm/evm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EVMChainWallet = exports.EVMVM = void 0;
|
|
3
|
+
exports.EVMChainWallet = exports.EVMChainAddress = exports.EVMVM = void 0;
|
|
4
4
|
const walletBip32_1 = require("../walletBip32");
|
|
5
5
|
const IChainWallet_1 = require("../IChainWallet");
|
|
6
6
|
const vm_1 = require("../vm");
|
|
@@ -12,6 +12,46 @@ const viem_1 = require("viem");
|
|
|
12
12
|
const smartWallet_1 = require("./smartWallet");
|
|
13
13
|
const price_1 = require("../price");
|
|
14
14
|
const accounts_1 = require("viem/accounts");
|
|
15
|
+
const createEvmPublicClient = (config) => (0, viem_1.createPublicClient)({
|
|
16
|
+
chain: (0, utils_1.fromChainToViemChain)(config),
|
|
17
|
+
transport: (0, viem_1.http)(config.rpcUrl),
|
|
18
|
+
});
|
|
19
|
+
const createEvmWalletClient = (config, account) => (0, viem_1.createWalletClient)({
|
|
20
|
+
account,
|
|
21
|
+
chain: (0, utils_1.fromChainToViemChain)(config),
|
|
22
|
+
transport: (0, viem_1.http)(config.rpcUrl),
|
|
23
|
+
});
|
|
24
|
+
const getEvmTransactionHistorySafe = async (connection, address) => {
|
|
25
|
+
try {
|
|
26
|
+
return await (0, transactionParsing_1.getEVMTransactionHistory)(connection, address);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const getEvmPrices = async (config, tokenAddresses) => {
|
|
33
|
+
const result = await (0, price_1.fetchPrices)({
|
|
34
|
+
vm: 'EVM',
|
|
35
|
+
chainId: config.chainId,
|
|
36
|
+
tokenAddresses,
|
|
37
|
+
});
|
|
38
|
+
if (result.error) {
|
|
39
|
+
throw new Error(result.error.message);
|
|
40
|
+
}
|
|
41
|
+
return result.data;
|
|
42
|
+
};
|
|
43
|
+
const getEvmNativeBalance = async (address, connection) => {
|
|
44
|
+
return await EVMVM.getNativeBalance(address, connection);
|
|
45
|
+
};
|
|
46
|
+
const getEvmTokenBalance = async (address, tokenAddress, connection) => {
|
|
47
|
+
return await EVMVM.getTokenBalance(address, tokenAddress, connection);
|
|
48
|
+
};
|
|
49
|
+
const discoverEvmTokens = async (address, config) => {
|
|
50
|
+
return await (0, utils_1.discoverTokens)(address, config);
|
|
51
|
+
};
|
|
52
|
+
const discoverEvmNFTs = async (address, config) => {
|
|
53
|
+
return await (0, utils_1.discoverNFTs)(address, config);
|
|
54
|
+
};
|
|
15
55
|
class EVMVM extends vm_1.VM {
|
|
16
56
|
derivationPath = "m/44'/60'/0'/0/";
|
|
17
57
|
constructor(seed) {
|
|
@@ -72,7 +112,8 @@ class EVMVM extends vm_1.VM {
|
|
|
72
112
|
return await (0, utils_1.getTokenBalance)(tokenAddress, address, connection);
|
|
73
113
|
}
|
|
74
114
|
static convertFromEntropyToPrivateKey = (entropy) => {
|
|
75
|
-
|
|
115
|
+
const p = ethers_1.ethers.id(entropy);
|
|
116
|
+
return p;
|
|
76
117
|
};
|
|
77
118
|
async discoverWallets(connection, options) {
|
|
78
119
|
const startTime = Date.now();
|
|
@@ -387,24 +428,46 @@ class EVMVM extends vm_1.VM {
|
|
|
387
428
|
}
|
|
388
429
|
}
|
|
389
430
|
exports.EVMVM = EVMVM;
|
|
431
|
+
class EVMChainAddress extends IChainWallet_1.ChainAddress {
|
|
432
|
+
constructor(config, address, index) {
|
|
433
|
+
const connection = createEvmPublicClient(config);
|
|
434
|
+
super(config, address, index);
|
|
435
|
+
this.connection = connection;
|
|
436
|
+
}
|
|
437
|
+
async getNativeBalance() {
|
|
438
|
+
return await getEvmNativeBalance(this.address, this.connection);
|
|
439
|
+
}
|
|
440
|
+
async getTokenBalance(tokenAddress) {
|
|
441
|
+
return await getEvmTokenBalance(this.address, tokenAddress, this.connection);
|
|
442
|
+
}
|
|
443
|
+
async discoverToken() {
|
|
444
|
+
return await discoverEvmTokens(this.address, this.config);
|
|
445
|
+
}
|
|
446
|
+
async discoverNFT() {
|
|
447
|
+
return await discoverEvmNFTs(this.address, this.config);
|
|
448
|
+
}
|
|
449
|
+
async getTransactionHistory() {
|
|
450
|
+
return await getEvmTransactionHistorySafe(this.connection, this.address);
|
|
451
|
+
}
|
|
452
|
+
async getPrices(tokenAddresses) {
|
|
453
|
+
return await getEvmPrices(this.config, tokenAddresses);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
exports.EVMChainAddress = EVMChainAddress;
|
|
390
457
|
class EVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
391
458
|
wallet;
|
|
392
459
|
smartWallet;
|
|
393
460
|
constructor(config, privateKey, index) {
|
|
394
461
|
privateKey = privateKey.startsWith('0x') ? privateKey : `0x${privateKey}`;
|
|
395
|
-
|
|
396
|
-
this.connection = (0, viem_1.createPublicClient)({
|
|
397
|
-
chain: (0, utils_1.fromChainToViemChain)(config),
|
|
398
|
-
transport: (0, viem_1.http)(config.rpcUrl)
|
|
399
|
-
});
|
|
462
|
+
const connection = createEvmPublicClient(config);
|
|
400
463
|
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
transport: (0, viem_1.http)(config.rpcUrl)
|
|
405
|
-
});
|
|
406
|
-
this.address = account.address;
|
|
464
|
+
const wallet = createEvmWalletClient(config, account);
|
|
465
|
+
const address = account.address;
|
|
466
|
+
super(config, address, privateKey, index);
|
|
407
467
|
this.privateKey = privateKey;
|
|
468
|
+
this.wallet = wallet;
|
|
469
|
+
this.connection = connection;
|
|
470
|
+
this.address = address;
|
|
408
471
|
}
|
|
409
472
|
isAASupportedByChain() {
|
|
410
473
|
return this.config.aaSupport?.enabled === true;
|
|
@@ -497,19 +560,19 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
|
497
560
|
return this.address;
|
|
498
561
|
}
|
|
499
562
|
async getNativeBalance() {
|
|
500
|
-
return await
|
|
563
|
+
return await getEvmNativeBalance(this.address, this.connection);
|
|
501
564
|
}
|
|
502
565
|
async getTokenBalance(tokenAddress) {
|
|
503
|
-
return await
|
|
566
|
+
return await getEvmTokenBalance(this.address, tokenAddress, this.connection);
|
|
504
567
|
}
|
|
505
568
|
async getTokenInfo(tokenAddress) {
|
|
506
569
|
return await EVMVM.getTokenInfo(tokenAddress, this.connection);
|
|
507
570
|
}
|
|
508
571
|
async discoverToken() {
|
|
509
|
-
return await (
|
|
572
|
+
return await discoverEvmTokens(this.address, this.config);
|
|
510
573
|
}
|
|
511
574
|
async discoverNFT() {
|
|
512
|
-
return await (
|
|
575
|
+
return await discoverEvmNFTs(this.address, this.config);
|
|
513
576
|
}
|
|
514
577
|
async transferNative(to, amount) {
|
|
515
578
|
const wallet = this.getWallet();
|
|
@@ -522,23 +585,10 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
|
522
585
|
async getTransactionHistory() {
|
|
523
586
|
const wallet = this.getWallet();
|
|
524
587
|
let res;
|
|
525
|
-
|
|
526
|
-
return await (0, transactionParsing_1.getEVMTransactionHistory)(this.connection, this.address);
|
|
527
|
-
}
|
|
528
|
-
catch (error) {
|
|
529
|
-
return [];
|
|
530
|
-
}
|
|
588
|
+
return await getEvmTransactionHistorySafe(this.connection, this.address);
|
|
531
589
|
}
|
|
532
590
|
async getPrices(tokenAddresses) {
|
|
533
|
-
|
|
534
|
-
vm: 'EVM',
|
|
535
|
-
chainId: this.config.chainId,
|
|
536
|
-
tokenAddresses,
|
|
537
|
-
});
|
|
538
|
-
if (result.error) {
|
|
539
|
-
throw new Error(result.error.message);
|
|
540
|
-
}
|
|
541
|
-
return result.data;
|
|
591
|
+
return await getEvmPrices(this.config, tokenAddresses);
|
|
542
592
|
}
|
|
543
593
|
async swap(tokenAddress, to, amount, slippage = 50) {
|
|
544
594
|
throw new Error("Not Implemented");
|
package/dist/evm/utils.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ export declare const ERC20_ABI: readonly [{
|
|
|
176
176
|
}];
|
|
177
177
|
}];
|
|
178
178
|
export declare const fromChainToViemChain: (config: ChainWalletConfig) => Chain;
|
|
179
|
+
export declare const createPublicClientFromChainConfig: (chain: ChainWalletConfig) => PublicClient;
|
|
179
180
|
export declare function viemReceiptToEthersReceipt(receipt: ViemTransactionReceipt): EthersTransactionReceipt;
|
|
180
181
|
export declare const getNativeBalance: (address: Hex, client: PublicClient) => Promise<Balance>;
|
|
181
182
|
export declare const getTokenInfo: (tokenAddress: Hex, client: PublicClient) => Promise<TokenInfo>;
|
package/dist/evm/utils.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.getNFTCollection = exports.discoverAllNFTs = exports.discoverNFTs = exports.transformEVMNFTToUnified = exports.discoverTokens = exports.safeApprove = exports.resetAllowance = exports.checkAndApprove = exports.approveTokenUnlimited = exports.approveToken = exports.isAllowanceSufficient = exports.checkAllowance = exports.estimateGas = exports.getGasPrices = exports.sendERC20Token = exports.sendNativeToken = exports.signSendAndConfirm = exports.getTokenBalance = exports.getTokenInfo = exports.getNativeBalance = exports.fromChainToViemChain = exports.ERC20_ABI = exports.DESERIALIZED_SUPPORTED_CHAINS = void 0;
|
|
6
|
+
exports.getNFTCollection = exports.discoverAllNFTs = exports.discoverNFTs = exports.transformEVMNFTToUnified = exports.discoverTokens = exports.safeApprove = exports.resetAllowance = exports.checkAndApprove = exports.approveTokenUnlimited = exports.approveToken = exports.isAllowanceSufficient = exports.checkAllowance = exports.estimateGas = exports.getGasPrices = exports.sendERC20Token = exports.sendNativeToken = exports.signSendAndConfirm = exports.getTokenBalance = exports.getTokenInfo = exports.getNativeBalance = exports.createPublicClientFromChainConfig = exports.fromChainToViemChain = exports.ERC20_ABI = exports.DESERIALIZED_SUPPORTED_CHAINS = void 0;
|
|
7
7
|
exports.viemReceiptToEthersReceipt = viemReceiptToEthersReceipt;
|
|
8
8
|
exports.calcGasTotal = calcGasTotal;
|
|
9
9
|
exports.toPrecisionWithoutTrailingZeros = toPrecisionWithoutTrailingZeros;
|
|
@@ -112,6 +112,13 @@ const fromChainToViemChain = (config) => {
|
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
114
|
exports.fromChainToViemChain = fromChainToViemChain;
|
|
115
|
+
const createPublicClientFromChainConfig = (chain) => {
|
|
116
|
+
return (0, viem_1.createPublicClient)({
|
|
117
|
+
chain: (0, exports.fromChainToViemChain)(chain),
|
|
118
|
+
transport: (0, viem_1.http)(chain.rpcUrl)
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
exports.createPublicClientFromChainConfig = createPublicClientFromChainConfig;
|
|
115
122
|
function viemReceiptToEthersReceipt(receipt) {
|
|
116
123
|
return {
|
|
117
124
|
to: receipt.to ?? null,
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from "./walletBip32";
|
|
|
2
2
|
export * from "./types";
|
|
3
3
|
export * from "./vm";
|
|
4
4
|
export { EVMVM, EVMChainWallet, EVMSmartWallet } from "./evm";
|
|
5
|
-
export { SVMVM, SVMChainWallet, } from "./svm";
|
|
5
|
+
export { SVMVM, SVMChainWallet, SVMChainAddress } from "./svm";
|
|
6
6
|
export * as evm from "./evm";
|
|
7
7
|
export * as svm from "./svm";
|
|
8
8
|
export * from "./constant";
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.svm = exports.evm = exports.SVMChainWallet = exports.SVMVM = exports.EVMSmartWallet = exports.EVMChainWallet = exports.EVMVM = void 0;
|
|
39
|
+
exports.svm = exports.evm = exports.SVMChainAddress = exports.SVMChainWallet = exports.SVMVM = exports.EVMSmartWallet = exports.EVMChainWallet = exports.EVMVM = void 0;
|
|
40
40
|
__exportStar(require("./walletBip32"), exports);
|
|
41
41
|
__exportStar(require("./types"), exports);
|
|
42
42
|
__exportStar(require("./vm"), exports);
|
|
@@ -47,6 +47,7 @@ Object.defineProperty(exports, "EVMSmartWallet", { enumerable: true, get: functi
|
|
|
47
47
|
var svm_1 = require("./svm");
|
|
48
48
|
Object.defineProperty(exports, "SVMVM", { enumerable: true, get: function () { return svm_1.SVMVM; } });
|
|
49
49
|
Object.defineProperty(exports, "SVMChainWallet", { enumerable: true, get: function () { return svm_1.SVMChainWallet; } });
|
|
50
|
+
Object.defineProperty(exports, "SVMChainAddress", { enumerable: true, get: function () { return svm_1.SVMChainAddress; } });
|
|
50
51
|
exports.evm = __importStar(require("./evm"));
|
|
51
52
|
exports.svm = __importStar(require("./svm"));
|
|
52
53
|
__exportStar(require("./constant"), exports);
|
package/dist/svm/svm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
2
|
import { VM } from "../vm";
|
|
3
|
-
import { ChainWallet } from "../IChainWallet";
|
|
3
|
+
import { ChainAddress, ChainWallet } from "../IChainWallet";
|
|
4
4
|
import { Balance, ChainWalletConfig, UserTokenBalance, TokenInfo, TransactionResult, NFT, WalletDiscoveryOptions, WalletDiscoveryResult, PocketDiscoveryOptions } from "../types";
|
|
5
5
|
import { JupiterQuoteResponse } from "./utils";
|
|
6
6
|
import { PriceResponse } from "../price.types";
|
|
@@ -36,6 +36,15 @@ export declare class SVMVM extends VM<PublicKey, Keypair, Connection> {
|
|
|
36
36
|
discoverPockets(connection: Connection, options?: PocketDiscoveryOptions): Promise<WalletDiscoveryResult>;
|
|
37
37
|
private checkPocketBalance;
|
|
38
38
|
}
|
|
39
|
+
export declare class SVMChainAddress extends ChainAddress<PublicKey, Connection> {
|
|
40
|
+
constructor(config: ChainWalletConfig, address: PublicKey, index?: number);
|
|
41
|
+
getNativeBalance(): Promise<Balance>;
|
|
42
|
+
getTokenBalance(tokenAddress: PublicKey): Promise<Balance>;
|
|
43
|
+
discoverToken(): Promise<UserTokenBalance<PublicKey>[]>;
|
|
44
|
+
discoverNFT(): Promise<NFT[]>;
|
|
45
|
+
getTransactionHistory(): Promise<SVMTransactionHistoryItem[]>;
|
|
46
|
+
getPrices(tokenAddresses: string[]): Promise<PriceResponse>;
|
|
47
|
+
}
|
|
39
48
|
export declare class SVMChainWallet extends ChainWallet<PublicKey, Keypair, Connection> {
|
|
40
49
|
constructor(config: ChainWalletConfig, privateKey: Keypair, index: number);
|
|
41
50
|
generateAddress(): PublicKey;
|
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 = 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,33 @@ 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
|
+
const getSvmNativeBalanceForAddress = async (address, connection) => {
|
|
20
|
+
return await SVMVM.getNativeBalance(address, connection);
|
|
21
|
+
};
|
|
22
|
+
const getSvmTokenBalanceForAddress = async (address, tokenAddress, connection) => {
|
|
23
|
+
return await SVMVM.getTokenBalance(address, tokenAddress, connection);
|
|
24
|
+
};
|
|
25
|
+
const discoverSvmTokens = async (address, connection) => {
|
|
26
|
+
return await (0, utils_1.discoverTokens)(address, connection);
|
|
27
|
+
};
|
|
28
|
+
const discoverSvmNFTs = async (address, connection) => {
|
|
29
|
+
return await (0, utils_1.fetchWalletNfts)(address, connection);
|
|
30
|
+
};
|
|
31
|
+
const getSvmTransactionHistoryForAddress = async (connection, address) => {
|
|
32
|
+
return await (0, transactionParsing_1.getSVMTransactionHistory)(connection, address);
|
|
33
|
+
};
|
|
34
|
+
const getSvmPricesForTokens = async (config, tokenAddresses) => {
|
|
35
|
+
const result = await (0, price_1.fetchPrices)({
|
|
36
|
+
vm: 'SVM',
|
|
37
|
+
chainId: config.chainId,
|
|
38
|
+
tokenAddresses,
|
|
39
|
+
});
|
|
40
|
+
if (result.error) {
|
|
41
|
+
throw new Error(result.error.message);
|
|
42
|
+
}
|
|
43
|
+
return result.data;
|
|
44
|
+
};
|
|
18
45
|
class SVMVM extends vm_1.VM {
|
|
19
46
|
getTokenInfo = utils_1.getTokenInfo;
|
|
20
47
|
static getTokenInfo = utils_1.getTokenInfo;
|
|
@@ -27,7 +54,7 @@ class SVMVM extends vm_1.VM {
|
|
|
27
54
|
return false;
|
|
28
55
|
}
|
|
29
56
|
}
|
|
30
|
-
derivationPath = "m/44'/501'/";
|
|
57
|
+
derivationPath = "m/44'/501'/0'/";
|
|
31
58
|
constructor(seed) {
|
|
32
59
|
super(seed, "SVM");
|
|
33
60
|
}
|
|
@@ -330,12 +357,39 @@ class SVMVM extends vm_1.VM {
|
|
|
330
357
|
}
|
|
331
358
|
}
|
|
332
359
|
exports.SVMVM = SVMVM;
|
|
360
|
+
class SVMChainAddress extends IChainWallet_1.ChainAddress {
|
|
361
|
+
constructor(config, address, index) {
|
|
362
|
+
const connection = createSvmConnection(config);
|
|
363
|
+
super(config, address, index);
|
|
364
|
+
this.connection = connection;
|
|
365
|
+
}
|
|
366
|
+
async getNativeBalance() {
|
|
367
|
+
return await getSvmNativeBalanceForAddress(this.address, this.connection);
|
|
368
|
+
}
|
|
369
|
+
async getTokenBalance(tokenAddress) {
|
|
370
|
+
return await getSvmTokenBalanceForAddress(this.address, tokenAddress, this.connection);
|
|
371
|
+
}
|
|
372
|
+
async discoverToken() {
|
|
373
|
+
return await discoverSvmTokens(this.address, this.connection);
|
|
374
|
+
}
|
|
375
|
+
async discoverNFT() {
|
|
376
|
+
return await discoverSvmNFTs(this.address, this.connection);
|
|
377
|
+
}
|
|
378
|
+
async getTransactionHistory() {
|
|
379
|
+
return await getSvmTransactionHistoryForAddress(this.connection, this.address);
|
|
380
|
+
}
|
|
381
|
+
async getPrices(tokenAddresses) {
|
|
382
|
+
return await getSvmPricesForTokens(this.config, tokenAddresses);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
exports.SVMChainAddress = SVMChainAddress;
|
|
333
386
|
class SVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
334
387
|
constructor(config, privateKey, index) {
|
|
335
|
-
|
|
388
|
+
const address = privateKey.publicKey;
|
|
389
|
+
super(config, address, privateKey, index);
|
|
336
390
|
this.address = privateKey.publicKey;
|
|
337
391
|
this.privateKey = privateKey;
|
|
338
|
-
this.connection =
|
|
392
|
+
this.connection = createSvmConnection(config);
|
|
339
393
|
}
|
|
340
394
|
generateAddress() {
|
|
341
395
|
return this.address;
|
|
@@ -344,18 +398,16 @@ class SVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
|
344
398
|
return web3_js_1.Keypair.fromSeed(Buffer.from(entropy));
|
|
345
399
|
};
|
|
346
400
|
async getNativeBalance() {
|
|
347
|
-
return await
|
|
401
|
+
return await getSvmNativeBalanceForAddress(this.address, this.connection);
|
|
348
402
|
}
|
|
349
403
|
async getTokenBalance(tokenAddress) {
|
|
350
|
-
return await
|
|
404
|
+
return await getSvmTokenBalanceForAddress(this.address, tokenAddress, this.connection);
|
|
351
405
|
}
|
|
352
406
|
async discoverToken() {
|
|
353
|
-
|
|
354
|
-
return tokens;
|
|
407
|
+
return await discoverSvmTokens(this.address, this.connection);
|
|
355
408
|
}
|
|
356
409
|
async discoverNFT() {
|
|
357
|
-
|
|
358
|
-
return nfts;
|
|
410
|
+
return await discoverSvmNFTs(this.address, this.connection);
|
|
359
411
|
}
|
|
360
412
|
async transferNative(to, amount) {
|
|
361
413
|
const transaction = await (0, utils_1.getTransferNativeTransaction)(this.privateKey, to, amount, this.connection);
|
|
@@ -377,22 +429,13 @@ class SVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
|
377
429
|
return await SVMVM.signAndSendTransaction(transaction, this.connection, this.privateKey);
|
|
378
430
|
}
|
|
379
431
|
async getTransactionHistory() {
|
|
380
|
-
|
|
381
|
-
return history;
|
|
432
|
+
return await getSvmTransactionHistoryForAddress(this.connection, this.address);
|
|
382
433
|
}
|
|
383
434
|
async getTokenInfo(tokenAddress) {
|
|
384
435
|
return await SVMVM.getTokenInfo(tokenAddress, this.connection);
|
|
385
436
|
}
|
|
386
437
|
async getPrices(tokenAddresses) {
|
|
387
|
-
|
|
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;
|
|
438
|
+
return await getSvmPricesForTokens(this.config, tokenAddresses);
|
|
396
439
|
}
|
|
397
440
|
async swap(fromToken, toToken, amount, slippage = 50) {
|
|
398
441
|
try {
|
package/dist/test.js
CHANGED
|
@@ -233,5 +233,12 @@ 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
|
+
testEntropy();
|
|
236
243
|
const RPC_URL = chainConfig.rpcUrl;
|
|
237
244
|
const connection = new web3_js_1.Connection(RPC_URL);
|
package/package.json
CHANGED
package/utils/IChainWallet.ts
CHANGED
|
@@ -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
|
|
7
|
-
|
|
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,
|
|
13
|
+
constructor(config: ChainWalletConfig, address: AddressType, index?: number) {
|
|
14
14
|
this.config = config;
|
|
15
|
-
this.
|
|
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
|
}
|