@deserialize/multi-vm-wallet 1.5.35 → 1.6.1
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/constant.js +54 -4
- package/dist/evm/evm.js +1 -1
- package/dist/savings/evm-savings.js +6 -4
- package/dist/savings/multi-chain-savings.d.ts +4 -0
- package/dist/savings/multi-chain-savings.js +51 -7
- package/dist/savings/saving-manager.d.ts +1 -1
- package/dist/savings/saving-manager.js +13 -14
- package/dist/savings/savings-operations.js +4 -2
- package/dist/savings/svm-savings.d.ts +1 -0
- package/dist/savings/svm-savings.js +16 -8
- package/dist/test.js +2 -0
- package/dist/types.d.ts +2 -1
- package/dist/utils.d.ts +30 -1
- package/dist/utils.js +199 -1
- package/dist/walletBip32.js +1 -1
- package/package.json +1 -1
- package/utils/constant.ts +58 -4
- package/utils/evm/evm.ts +1 -1
- package/utils/savings/evm-savings.ts +6 -4
- package/utils/savings/multi-chain-savings.ts +71 -8
- package/utils/savings/saving-manager.ts +20 -20
- package/utils/savings/savings-operations.ts +11 -9
- package/utils/savings/svm-savings.ts +17 -8
- package/utils/test.ts +1 -1
- package/utils/types.ts +2 -1
- package/utils/utils.ts +250 -4
- package/utils/walletBip32.ts +5 -2
package/dist/constant.js
CHANGED
|
@@ -16,7 +16,21 @@ exports.DefaultChains = [{
|
|
|
16
16
|
logoUrl: "https://solana.com/src/img/branding/solanaLogoMark.svg",
|
|
17
17
|
vmType: "SVM",
|
|
18
18
|
savings: {
|
|
19
|
-
|
|
19
|
+
supported: true,
|
|
20
|
+
tokens: [
|
|
21
|
+
{
|
|
22
|
+
name: "USDC",
|
|
23
|
+
symbol: "USDC",
|
|
24
|
+
decimals: 6,
|
|
25
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "USDT",
|
|
29
|
+
symbol: "USDT",
|
|
30
|
+
decimals: 6,
|
|
31
|
+
address: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
20
34
|
}
|
|
21
35
|
},
|
|
22
36
|
{
|
|
@@ -33,6 +47,7 @@ exports.DefaultChains = [{
|
|
|
33
47
|
logoUrl: "https://push.org/assets/website/favicons/favicon.svg",
|
|
34
48
|
vmType: "EVM",
|
|
35
49
|
savings: {
|
|
50
|
+
supported: false,
|
|
36
51
|
tokens: []
|
|
37
52
|
}
|
|
38
53
|
},
|
|
@@ -48,7 +63,23 @@ exports.DefaultChains = [{
|
|
|
48
63
|
},
|
|
49
64
|
testnet: false,
|
|
50
65
|
logoUrl: "https://etherscan.io/images/svg/brands/ethereum-original-light.svg",
|
|
51
|
-
vmType: "EVM"
|
|
66
|
+
vmType: "EVM",
|
|
67
|
+
savings: {
|
|
68
|
+
supported: true,
|
|
69
|
+
tokens: [{
|
|
70
|
+
name: "USDC",
|
|
71
|
+
symbol: "USDC",
|
|
72
|
+
decimals: 6,
|
|
73
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "USDT",
|
|
77
|
+
symbol: "USDT",
|
|
78
|
+
decimals: 6,
|
|
79
|
+
address: "0xdac17f958d2ee523a2206206994597c13d831ec7"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
52
83
|
}, {
|
|
53
84
|
chainId: 56,
|
|
54
85
|
name: "BSC",
|
|
@@ -63,7 +94,15 @@ exports.DefaultChains = [{
|
|
|
63
94
|
logoUrl: "https://bscscan.com/assets/bsc/images/svg/logos/token-light.svg?v=25.10.5.0",
|
|
64
95
|
vmType: "EVM",
|
|
65
96
|
savings: {
|
|
66
|
-
|
|
97
|
+
supported: true,
|
|
98
|
+
tokens: [
|
|
99
|
+
{
|
|
100
|
+
name: "BUSD",
|
|
101
|
+
symbol: "BUSD",
|
|
102
|
+
decimals: 6,
|
|
103
|
+
address: "0x55d398326f99059fF775485246999027B3197955"
|
|
104
|
+
}
|
|
105
|
+
]
|
|
67
106
|
}
|
|
68
107
|
},
|
|
69
108
|
{
|
|
@@ -80,7 +119,15 @@ exports.DefaultChains = [{
|
|
|
80
119
|
logoUrl: "https://avatars.githubusercontent.com/u/108554348?s=200&v=4",
|
|
81
120
|
vmType: "EVM",
|
|
82
121
|
savings: {
|
|
83
|
-
|
|
122
|
+
supported: true,
|
|
123
|
+
tokens: [
|
|
124
|
+
{
|
|
125
|
+
name: "USDC",
|
|
126
|
+
symbol: "USDC",
|
|
127
|
+
decimals: 6,
|
|
128
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
84
131
|
}
|
|
85
132
|
},
|
|
86
133
|
{
|
|
@@ -97,6 +144,7 @@ exports.DefaultChains = [{
|
|
|
97
144
|
logoUrl: "https://avatars.githubusercontent.com/u/119917794?s=280&v=4",
|
|
98
145
|
vmType: "EVM",
|
|
99
146
|
savings: {
|
|
147
|
+
supported: false,
|
|
100
148
|
tokens: []
|
|
101
149
|
}
|
|
102
150
|
},
|
|
@@ -114,6 +162,7 @@ exports.DefaultChains = [{
|
|
|
114
162
|
logoUrl: "https://avatars.githubusercontent.com/u/58791460?s=280&v=4",
|
|
115
163
|
vmType: "EVM",
|
|
116
164
|
savings: {
|
|
165
|
+
supported: false,
|
|
117
166
|
tokens: []
|
|
118
167
|
}
|
|
119
168
|
},
|
|
@@ -131,6 +180,7 @@ exports.DefaultChains = [{
|
|
|
131
180
|
logoUrl: "https://polygonscan.com/images/svg/brands/polygon-light.svg?v=0.0.36",
|
|
132
181
|
vmType: "EVM",
|
|
133
182
|
savings: {
|
|
183
|
+
supported: false,
|
|
134
184
|
tokens: []
|
|
135
185
|
}
|
|
136
186
|
}
|
package/dist/evm/evm.js
CHANGED
|
@@ -397,7 +397,7 @@ class EVMVM extends vm_1.VM {
|
|
|
397
397
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
398
398
|
try {
|
|
399
399
|
const pocketIndex = accountIndex + 1;
|
|
400
|
-
const derivationPath = `m/44'/60'/${pocketIndex}'/0/${walletIndex}
|
|
400
|
+
const derivationPath = `m/44'/60'/${pocketIndex}'/0/${walletIndex}`;
|
|
401
401
|
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(this.seed, walletIndex, `m/44'/60'/${pocketIndex}'/0/`);
|
|
402
402
|
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
403
403
|
const address = wallet.address;
|
|
@@ -42,9 +42,10 @@ class EVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
42
42
|
this.checkNotDisposed();
|
|
43
43
|
validation_1.SavingsValidation.validateAccountIndex(accountIndex);
|
|
44
44
|
const pocketIndex = accountIndex + 1;
|
|
45
|
-
const
|
|
45
|
+
const derivationPathBase = `${this.derivationPathBase}${pocketIndex}'/0/`;
|
|
46
|
+
const derivationPath = `${derivationPathBase}${this.walletIndex}'`;
|
|
46
47
|
const seed = (0, walletBip32_1.mnemonicToSeed)(this.mnemonic);
|
|
47
|
-
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, this.walletIndex,
|
|
48
|
+
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, this.walletIndex, derivationPathBase);
|
|
48
49
|
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
49
50
|
const pocket = {
|
|
50
51
|
privateKey,
|
|
@@ -57,9 +58,10 @@ class EVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
57
58
|
}
|
|
58
59
|
getMainWallet() {
|
|
59
60
|
this.checkNotDisposed();
|
|
60
|
-
const
|
|
61
|
+
const derivationPathBase = `${this.derivationPathBase}0'/0/`;
|
|
62
|
+
const derivationPath = `${derivationPathBase}${this.walletIndex}'`;
|
|
61
63
|
const seed = (0, walletBip32_1.mnemonicToSeed)(this.mnemonic);
|
|
62
|
-
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, this.walletIndex,
|
|
64
|
+
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, this.walletIndex, derivationPathBase);
|
|
63
65
|
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
64
66
|
return {
|
|
65
67
|
privateKey,
|
|
@@ -17,6 +17,7 @@ export interface PocketBalance {
|
|
|
17
17
|
balances: {
|
|
18
18
|
token: string;
|
|
19
19
|
balance: Balance;
|
|
20
|
+
balanceInUsd: number;
|
|
20
21
|
}[];
|
|
21
22
|
}
|
|
22
23
|
export declare class MultiChainSavingsManager {
|
|
@@ -25,6 +26,9 @@ export declare class MultiChainSavingsManager {
|
|
|
25
26
|
private evmManagers;
|
|
26
27
|
private svmManagers;
|
|
27
28
|
private chainConfigs;
|
|
29
|
+
private getTokenKey;
|
|
30
|
+
private normalizePriceMap;
|
|
31
|
+
private getPriceMap;
|
|
28
32
|
constructor(mnemonic: string, chains: ChainConfig[], walletIndex?: number);
|
|
29
33
|
addChain(chain: ChainConfig): void;
|
|
30
34
|
removeChain(chainId: string): void;
|
|
@@ -3,12 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MultiChainSavingsManager = void 0;
|
|
4
4
|
const evm_savings_1 = require("./evm-savings");
|
|
5
5
|
const svm_savings_1 = require("./svm-savings");
|
|
6
|
+
const price_1 = require("../price");
|
|
6
7
|
class MultiChainSavingsManager {
|
|
7
8
|
mnemonic;
|
|
8
9
|
walletIndex;
|
|
9
10
|
evmManagers = new Map();
|
|
10
11
|
svmManagers = new Map();
|
|
11
12
|
chainConfigs = new Map();
|
|
13
|
+
getTokenKey(tokenAddress, chainType) {
|
|
14
|
+
if (chainType === 'EVM') {
|
|
15
|
+
return tokenAddress.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
return tokenAddress;
|
|
18
|
+
}
|
|
19
|
+
normalizePriceMap(prices, chainType) {
|
|
20
|
+
const priceMap = new Map();
|
|
21
|
+
for (const item of prices) {
|
|
22
|
+
if (!item?.tokenAddress || typeof item.price !== 'number')
|
|
23
|
+
continue;
|
|
24
|
+
priceMap.set(this.getTokenKey(item.tokenAddress, chainType), item.price);
|
|
25
|
+
}
|
|
26
|
+
return priceMap;
|
|
27
|
+
}
|
|
28
|
+
async getPriceMap(chain, tokenAddresses) {
|
|
29
|
+
const chainWithId = chain.config;
|
|
30
|
+
if (typeof chainWithId.chainId !== 'number') {
|
|
31
|
+
return new Map();
|
|
32
|
+
}
|
|
33
|
+
const uniqueTokenAddresses = Array.from(new Set(tokenAddresses));
|
|
34
|
+
const priceResult = await (0, price_1.fetchPrices)({
|
|
35
|
+
vm: chain.type,
|
|
36
|
+
chainId: chainWithId.chainId,
|
|
37
|
+
tokenAddresses: uniqueTokenAddresses
|
|
38
|
+
});
|
|
39
|
+
return this.normalizePriceMap(priceResult.data?.prices ?? [], chain.type);
|
|
40
|
+
}
|
|
12
41
|
constructor(mnemonic, chains, walletIndex = 0) {
|
|
13
42
|
if (!mnemonic || typeof mnemonic !== 'string') {
|
|
14
43
|
throw new Error('Mnemonic must be a non-empty string');
|
|
@@ -29,9 +58,9 @@ class MultiChainSavingsManager {
|
|
|
29
58
|
if (this.chainConfigs.has(chain.id)) {
|
|
30
59
|
throw new Error(`Chain with id '${chain.id}' already exists`);
|
|
31
60
|
}
|
|
32
|
-
this.chainConfigs.set(chain.id, chain);
|
|
33
61
|
if (chain.type === 'EVM') {
|
|
34
62
|
const manager = new evm_savings_1.EVMSavingsManager(this.mnemonic, chain.config, this.walletIndex);
|
|
63
|
+
this.chainConfigs.set(chain.id, chain);
|
|
35
64
|
this.evmManagers.set(chain.id, manager);
|
|
36
65
|
}
|
|
37
66
|
else if (chain.type === 'SVM') {
|
|
@@ -40,6 +69,7 @@ class MultiChainSavingsManager {
|
|
|
40
69
|
throw new Error(`SVM chain '${chain.id}' must have rpcUrl in config`);
|
|
41
70
|
}
|
|
42
71
|
const manager = new svm_savings_1.SVMSavingsManager(this.mnemonic, config.rpcUrl, this.walletIndex);
|
|
72
|
+
this.chainConfigs.set(chain.id, chain);
|
|
43
73
|
this.svmManagers.set(chain.id, manager);
|
|
44
74
|
}
|
|
45
75
|
else {
|
|
@@ -95,14 +125,21 @@ class MultiChainSavingsManager {
|
|
|
95
125
|
const manager = this.evmManagers.get(chainId);
|
|
96
126
|
const balances = await manager.getPocketBalance(pocketIndex, tokens);
|
|
97
127
|
const pocket = manager.getPocket(pocketIndex);
|
|
128
|
+
const balanceRows = balances.map(b => ({
|
|
129
|
+
token: b.address === 'native' ? 'native' : b.address,
|
|
130
|
+
balance: b.balance
|
|
131
|
+
}));
|
|
132
|
+
const priceMap = await this.getPriceMap(chain, balanceRows.map(row => row.token));
|
|
98
133
|
return {
|
|
99
134
|
chainId,
|
|
100
135
|
chainType: 'EVM',
|
|
101
136
|
pocketIndex,
|
|
102
137
|
address: pocket.address,
|
|
103
|
-
balances:
|
|
104
|
-
token:
|
|
105
|
-
balance:
|
|
138
|
+
balances: balanceRows.map(row => ({
|
|
139
|
+
token: row.token,
|
|
140
|
+
balance: row.balance,
|
|
141
|
+
balanceInUsd: row.balance.formatted *
|
|
142
|
+
(priceMap.get(this.getTokenKey(row.token, 'EVM')) ?? 0)
|
|
106
143
|
}))
|
|
107
144
|
};
|
|
108
145
|
}
|
|
@@ -110,14 +147,21 @@ class MultiChainSavingsManager {
|
|
|
110
147
|
const manager = this.svmManagers.get(chainId);
|
|
111
148
|
const balances = await manager.getPocketBalance(pocketIndex, tokens);
|
|
112
149
|
const pocket = manager.getPocket(pocketIndex);
|
|
150
|
+
const balanceRows = balances.map(b => ({
|
|
151
|
+
token: b.address === 'native' ? 'native' : b.address.toBase58(),
|
|
152
|
+
balance: b.balance
|
|
153
|
+
}));
|
|
154
|
+
const priceMap = await this.getPriceMap(chain, balanceRows.map(row => row.token));
|
|
113
155
|
return {
|
|
114
156
|
chainId,
|
|
115
157
|
chainType: 'SVM',
|
|
116
158
|
pocketIndex,
|
|
117
159
|
address: pocket.address.toBase58(),
|
|
118
|
-
balances:
|
|
119
|
-
token:
|
|
120
|
-
balance:
|
|
160
|
+
balances: balanceRows.map(row => ({
|
|
161
|
+
token: row.token,
|
|
162
|
+
balance: row.balance,
|
|
163
|
+
balanceInUsd: row.balance.formatted *
|
|
164
|
+
(priceMap.get(this.getTokenKey(row.token, 'SVM')) ?? 0)
|
|
121
165
|
}))
|
|
122
166
|
};
|
|
123
167
|
}
|
|
@@ -42,5 +42,5 @@ export declare class SavingsManager extends BaseSavingsManager {
|
|
|
42
42
|
address: Hex | 'native';
|
|
43
43
|
balance: Balance;
|
|
44
44
|
}[]>;
|
|
45
|
-
sendToMainWallet(pocketIndex: number,
|
|
45
|
+
sendToMainWallet(pocketIndex: number, amount: bigint, token: Hex | "native"): Promise<TransactionResult>;
|
|
46
46
|
}
|
|
@@ -43,24 +43,25 @@ class BaseSavingsManager {
|
|
|
43
43
|
derivePocket(accountIndex) {
|
|
44
44
|
validation_1.SavingsValidation.validateAccountIndex(accountIndex);
|
|
45
45
|
const pocketIndex = accountIndex + 1;
|
|
46
|
-
const
|
|
47
|
-
const
|
|
46
|
+
const derivationPathBase = `m/44'/60'/${pocketIndex}'/0/`;
|
|
47
|
+
const derivationPath = `${derivationPathBase}${this.walletIndex}'`;
|
|
48
|
+
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)((0, walletBip32_1.mnemonicToSeed)(this.mnemonic), this.walletIndex, derivationPathBase);
|
|
48
49
|
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
49
50
|
const pocket = { privateKey, address: wallet.address, derivationPath, index: pocketIndex };
|
|
50
|
-
this.pockets.set(
|
|
51
|
+
this.pockets.set(accountIndex, pocket);
|
|
51
52
|
return pocket;
|
|
52
53
|
}
|
|
53
54
|
getMainWallet() {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
55
|
+
const mainWalletDerivationPathBase = `m/44'/60'/0'/0/`;
|
|
56
|
+
const mainWalletDerivationPath = `${mainWalletDerivationPathBase}${this.walletIndex}'`;
|
|
57
|
+
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)((0, walletBip32_1.mnemonicToSeed)(this.mnemonic), this.walletIndex, mainWalletDerivationPathBase);
|
|
56
58
|
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
57
59
|
return { privateKey, address: wallet.address, derivationPath: mainWalletDerivationPath };
|
|
58
60
|
}
|
|
59
61
|
getMainWalletAddress() {
|
|
60
62
|
if (this.masterAddress)
|
|
61
63
|
return this.masterAddress;
|
|
62
|
-
|
|
63
|
-
return new ethers_1.ethers.Wallet(privateKey).address;
|
|
64
|
+
return this.getMainWallet().address;
|
|
64
65
|
}
|
|
65
66
|
getPocket(accountIndex) {
|
|
66
67
|
if (!this.pockets.has(accountIndex)) {
|
|
@@ -88,7 +89,7 @@ class BaseSavingsManager {
|
|
|
88
89
|
return pocket.address.toLowerCase() === storedAddress.toLowerCase();
|
|
89
90
|
}
|
|
90
91
|
accountFromPocketId(p) {
|
|
91
|
-
return (0, accounts_1.privateKeyToAccount)(`0x${this.
|
|
92
|
+
return (0, accounts_1.privateKeyToAccount)(`0x${this.getPocket(p).privateKey}`);
|
|
92
93
|
}
|
|
93
94
|
clearPocket(accountIndex) {
|
|
94
95
|
validation_1.SavingsValidation.validateAccountIndex(accountIndex);
|
|
@@ -151,11 +152,9 @@ class SavingsManager extends BaseSavingsManager {
|
|
|
151
152
|
}));
|
|
152
153
|
return balancesList;
|
|
153
154
|
}
|
|
154
|
-
async sendToMainWallet(pocketIndex,
|
|
155
|
+
async sendToMainWallet(pocketIndex, amount, token) {
|
|
155
156
|
validation_1.SavingsValidation.validateAccountIndex(pocketIndex);
|
|
156
|
-
|
|
157
|
-
throw new Error(`Amount must be a positive number, got: ${amountInEther}`);
|
|
158
|
-
}
|
|
157
|
+
validation_1.SavingsValidation.validateAmount(amount, 'Transfer amount');
|
|
159
158
|
if (token !== 'native') {
|
|
160
159
|
validation_1.SavingsValidation.validateAddress(token, 'Token address');
|
|
161
160
|
}
|
|
@@ -167,9 +166,9 @@ class SavingsManager extends BaseSavingsManager {
|
|
|
167
166
|
chain: this.client.chain
|
|
168
167
|
});
|
|
169
168
|
if (token === "native") {
|
|
170
|
-
return await (0, evm_1.sendNativeToken)(walletClient, this.client, mainWalletAddress,
|
|
169
|
+
return await (0, evm_1.sendNativeToken)(walletClient, this.client, mainWalletAddress, amount);
|
|
171
170
|
}
|
|
172
|
-
const res = await (0, evm_1.sendERC20Token)(walletClient, this.client, token, mainWalletAddress,
|
|
171
|
+
const res = await (0, evm_1.sendERC20Token)(walletClient, this.client, token, mainWalletAddress, amount);
|
|
173
172
|
return res;
|
|
174
173
|
}
|
|
175
174
|
}
|
|
@@ -9,8 +9,9 @@ class SavingsOperations {
|
|
|
9
9
|
validation_1.SavingsValidation.validateMnemonic(mnemonic);
|
|
10
10
|
validation_1.SavingsValidation.validateAccountIndex(accountIndex);
|
|
11
11
|
validation_1.SavingsValidation.validateWalletIndex(walletIndex);
|
|
12
|
+
const pocketIndex = accountIndex + 1;
|
|
12
13
|
const seed = (0, walletBip32_1.mnemonicToSeed)(mnemonic);
|
|
13
|
-
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, walletIndex, `m/44'/60'/${
|
|
14
|
+
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, walletIndex, `m/44'/60'/${pocketIndex}'/0/`);
|
|
14
15
|
const wallet = new ethers_1.Wallet(privateKey, provider);
|
|
15
16
|
const address = wallet.address;
|
|
16
17
|
const cleanup = () => {
|
|
@@ -131,8 +132,9 @@ class SavingsOperations {
|
|
|
131
132
|
validation_1.SavingsValidation.validateMnemonic(mnemonic);
|
|
132
133
|
validation_1.SavingsValidation.validateAccountIndex(accountIndex);
|
|
133
134
|
validation_1.SavingsValidation.validateWalletIndex(walletIndex);
|
|
135
|
+
const pocketIndex = accountIndex + 1;
|
|
134
136
|
const seed = (0, walletBip32_1.mnemonicToSeed)(mnemonic);
|
|
135
|
-
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, walletIndex, `m/44'/60'/${
|
|
137
|
+
const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(seed, walletIndex, `m/44'/60'/${pocketIndex}'/0/`);
|
|
136
138
|
const wallet = new ethers_1.Wallet(privateKey);
|
|
137
139
|
const address = wallet.address;
|
|
138
140
|
return address;
|
|
@@ -10,6 +10,7 @@ export declare class SVMSavingsManager extends SavingsManager<PublicKey, Connect
|
|
|
10
10
|
get client(): Connection;
|
|
11
11
|
createClient(rpcUrl: string): Connection;
|
|
12
12
|
clearClient(): void;
|
|
13
|
+
private toSafeNumberAmount;
|
|
13
14
|
derivePocket(accountIndex: number): Pocket<PublicKey>;
|
|
14
15
|
getMainWallet(): {
|
|
15
16
|
privateKey: Keypair;
|
|
@@ -34,13 +34,20 @@ class SVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
34
34
|
clearClient() {
|
|
35
35
|
this._client = undefined;
|
|
36
36
|
}
|
|
37
|
+
toSafeNumberAmount(amount, label) {
|
|
38
|
+
if (amount > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
39
|
+
throw new Error(`${label} exceeds Number.MAX_SAFE_INTEGER and cannot be represented safely: ${amount}`);
|
|
40
|
+
}
|
|
41
|
+
return Number(amount);
|
|
42
|
+
}
|
|
37
43
|
derivePocket(accountIndex) {
|
|
38
44
|
this.checkNotDisposed();
|
|
39
45
|
validation_1.SavingsValidation.validateAccountIndex(accountIndex);
|
|
40
46
|
const pocketIndex = accountIndex + 1;
|
|
41
|
-
const
|
|
47
|
+
const derivationPathBase = `${this.derivationPathBase}${pocketIndex}'/0/`;
|
|
48
|
+
const derivationPath = `${derivationPathBase}${this.walletIndex}'`;
|
|
42
49
|
const seed = (0, walletBip32_1.mnemonicToSeed)(this.mnemonic);
|
|
43
|
-
const keypair = (0, walletBip32_1.SVMDeriveChildPrivateKey)(seed, this.walletIndex,
|
|
50
|
+
const keypair = (0, walletBip32_1.SVMDeriveChildPrivateKey)(seed, this.walletIndex, derivationPathBase);
|
|
44
51
|
const pocket = {
|
|
45
52
|
privateKey: keypair,
|
|
46
53
|
address: keypair.publicKey,
|
|
@@ -52,9 +59,10 @@ class SVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
52
59
|
}
|
|
53
60
|
getMainWallet() {
|
|
54
61
|
this.checkNotDisposed();
|
|
55
|
-
const
|
|
62
|
+
const derivationPathBase = `${this.derivationPathBase}0'/0/`;
|
|
63
|
+
const derivationPath = `${derivationPathBase}${this.walletIndex}'`;
|
|
56
64
|
const seed = (0, walletBip32_1.mnemonicToSeed)(this.mnemonic);
|
|
57
|
-
const keypair = (0, walletBip32_1.SVMDeriveChildPrivateKey)(seed, this.walletIndex,
|
|
65
|
+
const keypair = (0, walletBip32_1.SVMDeriveChildPrivateKey)(seed, this.walletIndex, derivationPathBase);
|
|
58
66
|
return {
|
|
59
67
|
privateKey: keypair,
|
|
60
68
|
address: keypair.publicKey,
|
|
@@ -120,7 +128,7 @@ class SVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
120
128
|
throw new Error(`Amount must be a positive bigint, got: ${amount}`);
|
|
121
129
|
}
|
|
122
130
|
const pocket = this.getPocket(pocketIndex);
|
|
123
|
-
const tx = await (0, svm_1.getTransferNativeTransaction)(mainWallet, pocket.address,
|
|
131
|
+
const tx = await (0, svm_1.getTransferNativeTransaction)(mainWallet, pocket.address, this.toSafeNumberAmount(amount, 'Native transfer amount'), this.client);
|
|
124
132
|
const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, mainWallet);
|
|
125
133
|
return { success: true, hash };
|
|
126
134
|
}
|
|
@@ -130,7 +138,7 @@ class SVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
130
138
|
throw new Error(`Amount must be a positive bigint, got: ${amount}`);
|
|
131
139
|
}
|
|
132
140
|
const pocket = this.getPocket(pocketIndex);
|
|
133
|
-
const tx = await (0, svm_1.getTransferTokenTransaction)(mainWallet, pocket.address, tokenInfo,
|
|
141
|
+
const tx = await (0, svm_1.getTransferTokenTransaction)(mainWallet, pocket.address, tokenInfo, this.toSafeNumberAmount(amount, 'Token transfer amount'), this.client);
|
|
134
142
|
const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, mainWallet);
|
|
135
143
|
return { success: true, hash };
|
|
136
144
|
}
|
|
@@ -160,11 +168,11 @@ class SVMSavingsManager extends savings_manager_1.SavingsManager {
|
|
|
160
168
|
const pocket = this.getPocket(pocketIndex);
|
|
161
169
|
const mainWalletAddress = this.getMainWalletAddress();
|
|
162
170
|
if (token === "native") {
|
|
163
|
-
const tx = await (0, svm_1.getTransferNativeTransaction)(pocket.privateKey, mainWalletAddress,
|
|
171
|
+
const tx = await (0, svm_1.getTransferNativeTransaction)(pocket.privateKey, mainWalletAddress, this.toSafeNumberAmount(amount, 'Native withdrawal amount'), this.client);
|
|
164
172
|
const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, pocket.privateKey);
|
|
165
173
|
return { success: true, hash };
|
|
166
174
|
}
|
|
167
|
-
const tx = await (0, svm_1.getTransferTokenTransaction)(pocket.privateKey, mainWalletAddress, token,
|
|
175
|
+
const tx = await (0, svm_1.getTransferTokenTransaction)(pocket.privateKey, mainWalletAddress, token, this.toSafeNumberAmount(amount, 'Token withdrawal amount'), this.client);
|
|
168
176
|
const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, pocket.privateKey);
|
|
169
177
|
return { success: true, hash };
|
|
170
178
|
}
|
package/dist/test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const web3_js_1 = require("@solana/web3.js");
|
|
4
|
+
const svm_1 = require("./svm");
|
|
4
5
|
const evm_1 = require("./evm");
|
|
5
6
|
const viem_1 = require("viem");
|
|
6
7
|
const chains_1 = require("viem/chains");
|
|
@@ -243,6 +244,7 @@ const testAddressClass = async () => {
|
|
|
243
244
|
const evmAddressClass = new evm_1.EVMChainAddress(evmChainConfig, "0xC9C1D854b82BA9b4FB6f6D58E9EF3d1fAEd601AA", 0);
|
|
244
245
|
const res = await evmAddressClass.getNativeBalance();
|
|
245
246
|
console.log('res: ', res);
|
|
247
|
+
svm_1.SVMVM.generateMnemonicFromPrivateKey;
|
|
246
248
|
};
|
|
247
249
|
testAddressClass();
|
|
248
250
|
const RPC_URL = chainConfig.rpcUrl;
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import { vmTypes } from "./types";
|
|
1
|
+
import { ChainWalletConfig, vmTypes } from "./types";
|
|
2
2
|
export declare const getPrivateKeyFromAnother: (privateKey: any, fromVm: vmTypes, toVm: vmTypes) => string | import("@solana/web3.js").Keypair | undefined;
|
|
3
|
+
export interface AddressPortfolioItem {
|
|
4
|
+
tokenAddress: string | "native";
|
|
5
|
+
symbol: string;
|
|
6
|
+
decimals: number;
|
|
7
|
+
balanceRaw: string;
|
|
8
|
+
balanceFormatted: number;
|
|
9
|
+
priceUsd: number | null;
|
|
10
|
+
valueUsd: number | null;
|
|
11
|
+
}
|
|
12
|
+
export interface AddressPortfolioResult {
|
|
13
|
+
address: string;
|
|
14
|
+
vmType: vmTypes;
|
|
15
|
+
chainId: number;
|
|
16
|
+
items: AddressPortfolioItem[];
|
|
17
|
+
totals: {
|
|
18
|
+
valueUsd: number;
|
|
19
|
+
pricedItems: number;
|
|
20
|
+
unpricedItems: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface AddressPortfolioParams {
|
|
24
|
+
chain: ChainWalletConfig;
|
|
25
|
+
address: string;
|
|
26
|
+
vmType?: vmTypes;
|
|
27
|
+
includeNative?: boolean;
|
|
28
|
+
tokenAddresses?: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare const detectVmTypeFromAddress: (address: string) => vmTypes;
|
|
31
|
+
export declare const getAddressPortfolioValue: (params: AddressPortfolioParams) => Promise<AddressPortfolioResult>;
|