@deserialize/multi-vm-wallet 1.5.22 → 1.5.32
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/constant.js +40 -48
- package/dist/evm/evm.d.ts +19 -1
- package/dist/evm/evm.js +88 -31
- 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 +17 -1
- package/dist/svm/svm.js +71 -21
- package/dist/test.js +7 -1
- package/dist/types.d.ts +4 -0
- package/dist/walletBip32.js +0 -3
- package/package.json +1 -1
- package/utils/IChainWallet.ts +76 -15
- package/utils/constant.ts +41 -51
- package/utils/evm/evm.ts +369 -290
- 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 +344 -24
- package/utils/test.ts +9 -5
- package/utils/types.ts +6 -2
- package/utils/utils.ts +7 -0
- package/utils/walletBip32.ts +3 -3
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/constant.js
CHANGED
|
@@ -3,32 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TRANSACTION_TYPE = exports.DefaultChains = void 0;
|
|
4
4
|
const chains_1 = require("viem/chains");
|
|
5
5
|
exports.DefaultChains = [{
|
|
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
|
-
chainId: 16661,
|
|
20
|
-
name: "0G",
|
|
21
|
-
rpcUrl: "https://evmrpc.0g.ai",
|
|
22
|
-
explorerUrl: "https://chainscan.0g.ai/",
|
|
23
|
-
nativeToken: {
|
|
24
|
-
name: "OG Mainnet",
|
|
25
|
-
symbol: "0G",
|
|
26
|
-
decimals: 18,
|
|
27
|
-
},
|
|
28
|
-
testnet: false,
|
|
29
|
-
logoUrl: "https://chainscan.0g.ai/static/media/zg-logo-new.b22d59dabf457524325ca81c29a4e055.svg",
|
|
30
|
-
vmType: "EVM"
|
|
31
|
-
}, {
|
|
32
6
|
chainId: 123456789,
|
|
33
7
|
name: "Solana",
|
|
34
8
|
rpcUrl: "https://solana-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
|
|
@@ -40,7 +14,10 @@ exports.DefaultChains = [{
|
|
|
40
14
|
},
|
|
41
15
|
testnet: false,
|
|
42
16
|
logoUrl: "https://solana.com/src/img/branding/solanaLogoMark.svg",
|
|
43
|
-
vmType: "SVM"
|
|
17
|
+
vmType: "SVM",
|
|
18
|
+
savings: {
|
|
19
|
+
tokens: []
|
|
20
|
+
}
|
|
44
21
|
},
|
|
45
22
|
{
|
|
46
23
|
chainId: 1,
|
|
@@ -67,7 +44,10 @@ exports.DefaultChains = [{
|
|
|
67
44
|
},
|
|
68
45
|
testnet: false,
|
|
69
46
|
logoUrl: "https://bscscan.com/assets/bsc/images/svg/logos/token-light.svg?v=25.10.5.0",
|
|
70
|
-
vmType: "EVM"
|
|
47
|
+
vmType: "EVM",
|
|
48
|
+
savings: {
|
|
49
|
+
tokens: []
|
|
50
|
+
}
|
|
71
51
|
},
|
|
72
52
|
{
|
|
73
53
|
chainId: chains_1.base.id,
|
|
@@ -81,35 +61,44 @@ exports.DefaultChains = [{
|
|
|
81
61
|
},
|
|
82
62
|
testnet: chains_1.base.testnet,
|
|
83
63
|
logoUrl: "https://avatars.githubusercontent.com/u/108554348?s=200&v=4",
|
|
84
|
-
vmType: "EVM"
|
|
64
|
+
vmType: "EVM",
|
|
65
|
+
savings: {
|
|
66
|
+
tokens: []
|
|
67
|
+
}
|
|
85
68
|
},
|
|
86
69
|
{
|
|
87
|
-
chainId:
|
|
88
|
-
name:
|
|
89
|
-
rpcUrl:
|
|
90
|
-
explorerUrl:
|
|
70
|
+
chainId: chains_1.arbitrum.id,
|
|
71
|
+
name: chains_1.arbitrum.name,
|
|
72
|
+
rpcUrl: chains_1.arbitrum.rpcUrls.default.http[0],
|
|
73
|
+
explorerUrl: chains_1.arbitrum.blockExplorers?.default.url,
|
|
91
74
|
nativeToken: {
|
|
92
|
-
name:
|
|
93
|
-
symbol:
|
|
94
|
-
decimals:
|
|
75
|
+
name: chains_1.arbitrum.nativeCurrency.name,
|
|
76
|
+
symbol: chains_1.arbitrum.nativeCurrency.symbol,
|
|
77
|
+
decimals: chains_1.arbitrum.nativeCurrency.decimals,
|
|
95
78
|
},
|
|
96
79
|
testnet: false,
|
|
97
|
-
logoUrl: "https://
|
|
98
|
-
vmType: "EVM"
|
|
80
|
+
logoUrl: "https://avatars.githubusercontent.com/u/119917794?s=280&v=4",
|
|
81
|
+
vmType: "EVM",
|
|
82
|
+
savings: {
|
|
83
|
+
tokens: []
|
|
84
|
+
}
|
|
99
85
|
},
|
|
100
86
|
{
|
|
101
|
-
chainId:
|
|
102
|
-
name:
|
|
103
|
-
rpcUrl:
|
|
104
|
-
explorerUrl:
|
|
87
|
+
chainId: chains_1.optimism.id,
|
|
88
|
+
name: chains_1.optimism.name,
|
|
89
|
+
rpcUrl: chains_1.optimism.rpcUrls.default.http[0],
|
|
90
|
+
explorerUrl: chains_1.optimism.blockExplorers?.default.url,
|
|
105
91
|
nativeToken: {
|
|
106
|
-
name:
|
|
107
|
-
symbol:
|
|
108
|
-
decimals:
|
|
92
|
+
name: chains_1.optimism.nativeCurrency.name,
|
|
93
|
+
symbol: chains_1.optimism.nativeCurrency.symbol,
|
|
94
|
+
decimals: chains_1.optimism.nativeCurrency.decimals,
|
|
109
95
|
},
|
|
110
96
|
testnet: false,
|
|
111
|
-
logoUrl: "https://
|
|
112
|
-
vmType: "EVM"
|
|
97
|
+
logoUrl: "https://avatars.githubusercontent.com/u/58791460?s=280&v=4",
|
|
98
|
+
vmType: "EVM",
|
|
99
|
+
savings: {
|
|
100
|
+
tokens: []
|
|
101
|
+
}
|
|
113
102
|
},
|
|
114
103
|
{
|
|
115
104
|
chainId: 137,
|
|
@@ -123,7 +112,10 @@ exports.DefaultChains = [{
|
|
|
123
112
|
},
|
|
124
113
|
testnet: false,
|
|
125
114
|
logoUrl: "https://polygonscan.com/images/svg/brands/polygon-light.svg?v=0.0.36",
|
|
126
|
-
vmType: "EVM"
|
|
115
|
+
vmType: "EVM",
|
|
116
|
+
savings: {
|
|
117
|
+
tokens: []
|
|
118
|
+
}
|
|
127
119
|
}
|
|
128
120
|
];
|
|
129
121
|
exports.TRANSACTION_TYPE = {
|
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";
|
|
@@ -7,6 +7,15 @@ import { Hex, WalletClient, PublicClient } from "viem";
|
|
|
7
7
|
import { EVMSmartWallet } from "./smartWallet";
|
|
8
8
|
import { SmartWalletOptions } from "./aa-service";
|
|
9
9
|
import { PriceResponse } from "../price.types";
|
|
10
|
+
import { Account } from "viem/accounts";
|
|
11
|
+
export declare const createEvmPublicClient: (config: ChainWalletConfig) => PublicClient;
|
|
12
|
+
export declare const createEvmWalletClient: (config: ChainWalletConfig, account: Account) => WalletClient;
|
|
13
|
+
export declare const getEvmTransactionHistorySafe: (connection: PublicClient, address: string) => Promise<EVMTransactionHistoryItem[]>;
|
|
14
|
+
export declare const getSvmPricesForTokens: (config: ChainWalletConfig, tokenAddresses: string[]) => Promise<PriceResponse>;
|
|
15
|
+
export declare const getEvmNativeBalance: (address: string, connection: PublicClient) => Promise<Balance>;
|
|
16
|
+
export declare const getEvmTokenBalance: (address: string, tokenAddress: string, connection: PublicClient) => Promise<Balance>;
|
|
17
|
+
export declare const discoverEvmTokens: (address: string, config: ChainWalletConfig) => Promise<UserTokenBalance<string>[]>;
|
|
18
|
+
export declare const discoverEvmNFTs: (address: string, config: ChainWalletConfig) => Promise<NFT[]>;
|
|
10
19
|
export declare class EVMVM extends VM<string, string, PublicClient> {
|
|
11
20
|
derivationPath: string;
|
|
12
21
|
constructor(seed: string);
|
|
@@ -29,6 +38,15 @@ export declare class EVMVM extends VM<string, string, PublicClient> {
|
|
|
29
38
|
discoverPockets(connection: JsonRpcProvider | PublicClient, options?: PocketDiscoveryOptions): Promise<WalletDiscoveryResult>;
|
|
30
39
|
private checkPocketBalance;
|
|
31
40
|
}
|
|
41
|
+
export declare class EVMChainAddress extends ChainAddress<string, PublicClient> {
|
|
42
|
+
constructor(config: ChainWalletConfig, address: string, index?: number);
|
|
43
|
+
getNativeBalance(): Promise<Balance>;
|
|
44
|
+
getTokenBalance(tokenAddress: string): Promise<Balance>;
|
|
45
|
+
discoverToken(): Promise<UserTokenBalance<string>[]>;
|
|
46
|
+
discoverNFT(): Promise<NFT[]>;
|
|
47
|
+
getTransactionHistory(): Promise<EVMTransactionHistoryItem[]>;
|
|
48
|
+
getPrices(tokenAddresses: string[]): Promise<PriceResponse>;
|
|
49
|
+
}
|
|
32
50
|
export declare class EVMChainWallet extends ChainWallet<string, string, PublicClient> {
|
|
33
51
|
wallet: WalletClient;
|
|
34
52
|
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 = exports.discoverEvmNFTs = exports.discoverEvmTokens = exports.getEvmTokenBalance = exports.getEvmNativeBalance = exports.getSvmPricesForTokens = exports.getEvmTransactionHistorySafe = exports.createEvmWalletClient = exports.createEvmPublicClient = 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,54 @@ 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
|
+
exports.createEvmPublicClient = createEvmPublicClient;
|
|
20
|
+
const createEvmWalletClient = (config, account) => (0, viem_1.createWalletClient)({
|
|
21
|
+
account,
|
|
22
|
+
chain: (0, utils_1.fromChainToViemChain)(config),
|
|
23
|
+
transport: (0, viem_1.http)(config.rpcUrl),
|
|
24
|
+
});
|
|
25
|
+
exports.createEvmWalletClient = createEvmWalletClient;
|
|
26
|
+
const getEvmTransactionHistorySafe = async (connection, address) => {
|
|
27
|
+
try {
|
|
28
|
+
return await (0, transactionParsing_1.getEVMTransactionHistory)(connection, address);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.getEvmTransactionHistorySafe = getEvmTransactionHistorySafe;
|
|
35
|
+
const getSvmPricesForTokens = async (config, tokenAddresses) => {
|
|
36
|
+
const result = await (0, price_1.fetchPrices)({
|
|
37
|
+
vm: 'EVM',
|
|
38
|
+
chainId: config.chainId,
|
|
39
|
+
tokenAddresses,
|
|
40
|
+
});
|
|
41
|
+
if (result.error) {
|
|
42
|
+
throw new Error(result.error.message);
|
|
43
|
+
}
|
|
44
|
+
return result.data;
|
|
45
|
+
};
|
|
46
|
+
exports.getSvmPricesForTokens = getSvmPricesForTokens;
|
|
47
|
+
const getEvmNativeBalance = async (address, connection) => {
|
|
48
|
+
return await EVMVM.getNativeBalance(address, connection);
|
|
49
|
+
};
|
|
50
|
+
exports.getEvmNativeBalance = getEvmNativeBalance;
|
|
51
|
+
const getEvmTokenBalance = async (address, tokenAddress, connection) => {
|
|
52
|
+
return await EVMVM.getTokenBalance(address, tokenAddress, connection);
|
|
53
|
+
};
|
|
54
|
+
exports.getEvmTokenBalance = getEvmTokenBalance;
|
|
55
|
+
const discoverEvmTokens = async (address, config) => {
|
|
56
|
+
return await (0, utils_1.discoverTokens)(address, config);
|
|
57
|
+
};
|
|
58
|
+
exports.discoverEvmTokens = discoverEvmTokens;
|
|
59
|
+
const discoverEvmNFTs = async (address, config) => {
|
|
60
|
+
return await (0, utils_1.discoverNFTs)(address, config);
|
|
61
|
+
};
|
|
62
|
+
exports.discoverEvmNFTs = discoverEvmNFTs;
|
|
15
63
|
class EVMVM extends vm_1.VM {
|
|
16
64
|
derivationPath = "m/44'/60'/0'/0/";
|
|
17
65
|
constructor(seed) {
|
|
@@ -388,24 +436,46 @@ class EVMVM extends vm_1.VM {
|
|
|
388
436
|
}
|
|
389
437
|
}
|
|
390
438
|
exports.EVMVM = EVMVM;
|
|
439
|
+
class EVMChainAddress extends IChainWallet_1.ChainAddress {
|
|
440
|
+
constructor(config, address, index) {
|
|
441
|
+
const connection = (0, exports.createEvmPublicClient)(config);
|
|
442
|
+
super(config, address, index);
|
|
443
|
+
this.connection = connection;
|
|
444
|
+
}
|
|
445
|
+
async getNativeBalance() {
|
|
446
|
+
return await (0, exports.getEvmNativeBalance)(this.address, this.connection);
|
|
447
|
+
}
|
|
448
|
+
async getTokenBalance(tokenAddress) {
|
|
449
|
+
return await (0, exports.getEvmTokenBalance)(this.address, tokenAddress, this.connection);
|
|
450
|
+
}
|
|
451
|
+
async discoverToken() {
|
|
452
|
+
return await (0, exports.discoverEvmTokens)(this.address, this.config);
|
|
453
|
+
}
|
|
454
|
+
async discoverNFT() {
|
|
455
|
+
return await (0, exports.discoverEvmNFTs)(this.address, this.config);
|
|
456
|
+
}
|
|
457
|
+
async getTransactionHistory() {
|
|
458
|
+
return await (0, exports.getEvmTransactionHistorySafe)(this.connection, this.address);
|
|
459
|
+
}
|
|
460
|
+
async getPrices(tokenAddresses) {
|
|
461
|
+
return await (0, exports.getSvmPricesForTokens)(this.config, tokenAddresses);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
exports.EVMChainAddress = EVMChainAddress;
|
|
391
465
|
class EVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
392
466
|
wallet;
|
|
393
467
|
smartWallet;
|
|
394
468
|
constructor(config, privateKey, index) {
|
|
395
469
|
privateKey = privateKey.startsWith('0x') ? privateKey : `0x${privateKey}`;
|
|
396
|
-
|
|
397
|
-
this.connection = (0, viem_1.createPublicClient)({
|
|
398
|
-
chain: (0, utils_1.fromChainToViemChain)(config),
|
|
399
|
-
transport: (0, viem_1.http)(config.rpcUrl)
|
|
400
|
-
});
|
|
470
|
+
const connection = (0, exports.createEvmPublicClient)(config);
|
|
401
471
|
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
transport: (0, viem_1.http)(config.rpcUrl)
|
|
406
|
-
});
|
|
407
|
-
this.address = account.address;
|
|
472
|
+
const wallet = (0, exports.createEvmWalletClient)(config, account);
|
|
473
|
+
const address = account.address;
|
|
474
|
+
super(config, address, privateKey, index);
|
|
408
475
|
this.privateKey = privateKey;
|
|
476
|
+
this.wallet = wallet;
|
|
477
|
+
this.connection = connection;
|
|
478
|
+
this.address = address;
|
|
409
479
|
}
|
|
410
480
|
isAASupportedByChain() {
|
|
411
481
|
return this.config.aaSupport?.enabled === true;
|
|
@@ -498,19 +568,19 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
|
498
568
|
return this.address;
|
|
499
569
|
}
|
|
500
570
|
async getNativeBalance() {
|
|
501
|
-
return await
|
|
571
|
+
return await (0, exports.getEvmNativeBalance)(this.address, this.connection);
|
|
502
572
|
}
|
|
503
573
|
async getTokenBalance(tokenAddress) {
|
|
504
|
-
return await
|
|
574
|
+
return await (0, exports.getEvmTokenBalance)(this.address, tokenAddress, this.connection);
|
|
505
575
|
}
|
|
506
576
|
async getTokenInfo(tokenAddress) {
|
|
507
577
|
return await EVMVM.getTokenInfo(tokenAddress, this.connection);
|
|
508
578
|
}
|
|
509
579
|
async discoverToken() {
|
|
510
|
-
return await (0,
|
|
580
|
+
return await (0, exports.discoverEvmTokens)(this.address, this.config);
|
|
511
581
|
}
|
|
512
582
|
async discoverNFT() {
|
|
513
|
-
return await (0,
|
|
583
|
+
return await (0, exports.discoverEvmNFTs)(this.address, this.config);
|
|
514
584
|
}
|
|
515
585
|
async transferNative(to, amount) {
|
|
516
586
|
const wallet = this.getWallet();
|
|
@@ -523,23 +593,10 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
|
|
|
523
593
|
async getTransactionHistory() {
|
|
524
594
|
const wallet = this.getWallet();
|
|
525
595
|
let res;
|
|
526
|
-
|
|
527
|
-
return await (0, transactionParsing_1.getEVMTransactionHistory)(this.connection, this.address);
|
|
528
|
-
}
|
|
529
|
-
catch (error) {
|
|
530
|
-
return [];
|
|
531
|
-
}
|
|
596
|
+
return await (0, exports.getEvmTransactionHistorySafe)(this.connection, this.address);
|
|
532
597
|
}
|
|
533
598
|
async getPrices(tokenAddresses) {
|
|
534
|
-
|
|
535
|
-
vm: 'EVM',
|
|
536
|
-
chainId: this.config.chainId,
|
|
537
|
-
tokenAddresses,
|
|
538
|
-
});
|
|
539
|
-
if (result.error) {
|
|
540
|
-
throw new Error(result.error.message);
|
|
541
|
-
}
|
|
542
|
-
return result.data;
|
|
599
|
+
return await (0, exports.getSvmPricesForTokens)(this.config, tokenAddresses);
|
|
543
600
|
}
|
|
544
601
|
async swap(tokenAddress, to, amount, slippage = 50) {
|
|
545
602
|
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,10 +1,17 @@
|
|
|
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";
|
|
7
7
|
import { SVMTransactionHistoryItem } from "./transactionParsing";
|
|
8
|
+
export declare const createSvmConnection: (config: ChainWalletConfig) => Connection;
|
|
9
|
+
export declare const getSvmNativeBalanceForAddress: (address: PublicKey, connection: Connection) => Promise<Balance>;
|
|
10
|
+
export declare const getSvmTokenBalanceForAddress: (address: PublicKey, tokenAddress: PublicKey, connection: Connection) => Promise<Balance>;
|
|
11
|
+
export declare const discoverSvmTokens: (address: PublicKey, connection: Connection) => Promise<UserTokenBalance<PublicKey>[]>;
|
|
12
|
+
export declare const discoverSvmNFTs: (address: PublicKey, connection: Connection) => Promise<NFT[]>;
|
|
13
|
+
export declare const getSvmTransactionHistoryForAddress: (connection: Connection, address: PublicKey) => Promise<SVMTransactionHistoryItem[]>;
|
|
14
|
+
export declare const getSvmPricesForTokens: (config: ChainWalletConfig, tokenAddresses: string[]) => Promise<PriceResponse>;
|
|
8
15
|
export declare class SVMVM extends VM<PublicKey, Keypair, Connection> {
|
|
9
16
|
getTokenInfo: (tokenAddress: PublicKey, connection: Connection, programId?: PublicKey) => Promise<TokenInfo>;
|
|
10
17
|
static getTokenInfo: (tokenAddress: PublicKey, connection: Connection, programId?: PublicKey) => Promise<TokenInfo>;
|
|
@@ -36,6 +43,15 @@ export declare class SVMVM extends VM<PublicKey, Keypair, Connection> {
|
|
|
36
43
|
discoverPockets(connection: Connection, options?: PocketDiscoveryOptions): Promise<WalletDiscoveryResult>;
|
|
37
44
|
private checkPocketBalance;
|
|
38
45
|
}
|
|
46
|
+
export declare class SVMChainAddress extends ChainAddress<PublicKey, Connection> {
|
|
47
|
+
constructor(config: ChainWalletConfig, address: PublicKey, index?: number);
|
|
48
|
+
getNativeBalance(): Promise<Balance>;
|
|
49
|
+
getTokenBalance(tokenAddress: PublicKey): Promise<Balance>;
|
|
50
|
+
discoverToken(): Promise<UserTokenBalance<PublicKey>[]>;
|
|
51
|
+
discoverNFT(): Promise<NFT[]>;
|
|
52
|
+
getTransactionHistory(): Promise<SVMTransactionHistoryItem[]>;
|
|
53
|
+
getPrices(tokenAddresses: string[]): Promise<PriceResponse>;
|
|
54
|
+
}
|
|
39
55
|
export declare class SVMChainWallet extends ChainWallet<PublicKey, Keypair, Connection> {
|
|
40
56
|
constructor(config: ChainWalletConfig, privateKey: Keypair, index: number);
|
|
41
57
|
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 = 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
|
-
|
|
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 =
|
|
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
|
|
408
|
+
return await (0, exports.getSvmNativeBalanceForAddress)(this.address, this.connection);
|
|
348
409
|
}
|
|
349
410
|
async getTokenBalance(tokenAddress) {
|
|
350
|
-
return await
|
|
411
|
+
return await (0, exports.getSvmTokenBalanceForAddress)(this.address, tokenAddress, this.connection);
|
|
351
412
|
}
|
|
352
413
|
async discoverToken() {
|
|
353
|
-
|
|
354
|
-
return tokens;
|
|
414
|
+
return await (0, exports.discoverSvmTokens)(this.address, this.connection);
|
|
355
415
|
}
|
|
356
416
|
async discoverNFT() {
|
|
357
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|