@deserialize/multi-vm-wallet 1.6.2 ā 1.6.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/constant.js +0 -36
- package/dist/evm/utils.d.ts +20 -2
- package/dist/evm/utils.js +25 -4
- package/dist/test.js +19 -25
- package/package.json +1 -1
- package/utils/constant.ts +21 -38
- package/utils/evm/utils.ts +45 -3
- package/utils/test.ts +49 -31
package/dist/constant.js
CHANGED
|
@@ -33,24 +33,6 @@ exports.DefaultChains = [{
|
|
|
33
33
|
]
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
-
{
|
|
37
|
-
chainId: 42101,
|
|
38
|
-
name: "Push Chain Donut Testnet",
|
|
39
|
-
rpcUrl: "https://evm.donut.rpc.push.org",
|
|
40
|
-
explorerUrl: "https://donut.push.network",
|
|
41
|
-
nativeToken: {
|
|
42
|
-
name: "PC",
|
|
43
|
-
symbol: "PC",
|
|
44
|
-
decimals: 18,
|
|
45
|
-
},
|
|
46
|
-
testnet: true,
|
|
47
|
-
logoUrl: "https://push.org/assets/website/favicons/favicon.svg",
|
|
48
|
-
vmType: "EVM",
|
|
49
|
-
savings: {
|
|
50
|
-
supported: false,
|
|
51
|
-
tokens: []
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
36
|
{
|
|
55
37
|
chainId: 1,
|
|
56
38
|
name: "Ethereum",
|
|
@@ -166,24 +148,6 @@ exports.DefaultChains = [{
|
|
|
166
148
|
tokens: []
|
|
167
149
|
}
|
|
168
150
|
},
|
|
169
|
-
{
|
|
170
|
-
chainId: 137,
|
|
171
|
-
name: "Polygon",
|
|
172
|
-
rpcUrl: "https://polygon-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
|
|
173
|
-
explorerUrl: "https://polygonscan.com",
|
|
174
|
-
nativeToken: {
|
|
175
|
-
name: "MATIC",
|
|
176
|
-
symbol: "MATIC",
|
|
177
|
-
decimals: 18,
|
|
178
|
-
},
|
|
179
|
-
testnet: false,
|
|
180
|
-
logoUrl: "https://polygonscan.com/images/svg/brands/polygon-light.svg?v=0.0.36",
|
|
181
|
-
vmType: "EVM",
|
|
182
|
-
savings: {
|
|
183
|
-
supported: false,
|
|
184
|
-
tokens: []
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
151
|
];
|
|
188
152
|
exports.TRANSACTION_TYPE = {
|
|
189
153
|
NATIVE_TRANSFER: 'NATIVE_TRANSFER',
|
package/dist/evm/utils.d.ts
CHANGED
|
@@ -181,6 +181,18 @@ export declare function viemReceiptToEthersReceipt(receipt: ViemTransactionRecei
|
|
|
181
181
|
export declare const getNativeBalance: (address: Hex, client: PublicClient) => Promise<Balance>;
|
|
182
182
|
export declare const getTokenInfo: (tokenAddress: Hex, client: PublicClient) => Promise<TokenInfo>;
|
|
183
183
|
export declare const getTokenBalance: (tokenAddress: Hex, walletAddress: Hex, client: PublicClient) => Promise<Balance>;
|
|
184
|
+
export declare const signAndSend: (walletClient: WalletClient, publicClient: PublicClient, params: {
|
|
185
|
+
to: Hex;
|
|
186
|
+
data?: Hex;
|
|
187
|
+
value?: bigint;
|
|
188
|
+
gas?: bigint;
|
|
189
|
+
nonce?: number;
|
|
190
|
+
maxFeePerGas?: bigint;
|
|
191
|
+
maxPriorityFeePerGas?: bigint;
|
|
192
|
+
}, confirmations?: number) => Promise<{
|
|
193
|
+
hash: Hex;
|
|
194
|
+
success: boolean;
|
|
195
|
+
}>;
|
|
184
196
|
export declare const signSendAndConfirm: (walletClient: WalletClient, publicClient: PublicClient, params: {
|
|
185
197
|
to: Hex;
|
|
186
198
|
data?: Hex;
|
|
@@ -190,8 +202,14 @@ export declare const signSendAndConfirm: (walletClient: WalletClient, publicClie
|
|
|
190
202
|
maxFeePerGas?: bigint;
|
|
191
203
|
maxPriorityFeePerGas?: bigint;
|
|
192
204
|
}, confirmations?: number) => Promise<TransactionResult>;
|
|
193
|
-
export declare const sendNativeToken: (walletClient: WalletClient, publicClient: PublicClient, to: Hex, amount: string | bigint, confirmations?: number) => Promise<
|
|
194
|
-
|
|
205
|
+
export declare const sendNativeToken: (walletClient: WalletClient, publicClient: PublicClient, to: Hex, amount: string | bigint, confirmations?: number) => Promise<{
|
|
206
|
+
hash: Hex;
|
|
207
|
+
success: boolean;
|
|
208
|
+
}>;
|
|
209
|
+
export declare const sendERC20Token: (walletClient: WalletClient, publicClient: PublicClient, tokenAddress: Hex, to: Hex, amount: bigint, confirmations?: number) => Promise<{
|
|
210
|
+
hash: Hex;
|
|
211
|
+
success: boolean;
|
|
212
|
+
}>;
|
|
195
213
|
export declare const getGasPrices: (client: PublicClient) => Promise<{
|
|
196
214
|
gasPrice: undefined;
|
|
197
215
|
maxFeePerGas: bigint;
|
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.createPublicClientFromChainConfig = 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.signAndSend = 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;
|
|
@@ -205,6 +205,27 @@ const getTokenBalance = async (tokenAddress, walletAddress, client) => {
|
|
|
205
205
|
};
|
|
206
206
|
};
|
|
207
207
|
exports.getTokenBalance = getTokenBalance;
|
|
208
|
+
const signAndSend = async (walletClient, publicClient, params, confirmations = 1) => {
|
|
209
|
+
if (walletClient.account === undefined) {
|
|
210
|
+
throw new Error("wallet Client is not Initialized with an Account");
|
|
211
|
+
}
|
|
212
|
+
const hash = await walletClient.sendTransaction({
|
|
213
|
+
to: params.to,
|
|
214
|
+
data: params.data,
|
|
215
|
+
value: params.value,
|
|
216
|
+
gas: params.gas,
|
|
217
|
+
nonce: params.nonce,
|
|
218
|
+
maxFeePerGas: params.maxFeePerGas,
|
|
219
|
+
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
220
|
+
account: walletClient.account,
|
|
221
|
+
chain: publicClient.chain,
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
hash,
|
|
225
|
+
success: !!hash,
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
exports.signAndSend = signAndSend;
|
|
208
229
|
const signSendAndConfirm = async (walletClient, publicClient, params, confirmations = 1) => {
|
|
209
230
|
if (walletClient.account === undefined) {
|
|
210
231
|
throw new Error("wallet Client is not Initialized with an Account");
|
|
@@ -218,7 +239,7 @@ const signSendAndConfirm = async (walletClient, publicClient, params, confirmati
|
|
|
218
239
|
maxFeePerGas: params.maxFeePerGas,
|
|
219
240
|
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
220
241
|
account: walletClient.account,
|
|
221
|
-
chain: publicClient.chain
|
|
242
|
+
chain: publicClient.chain,
|
|
222
243
|
});
|
|
223
244
|
const receipt = await publicClient.waitForTransactionReceipt({
|
|
224
245
|
hash,
|
|
@@ -238,7 +259,7 @@ const signSendAndConfirm = async (walletClient, publicClient, params, confirmati
|
|
|
238
259
|
exports.signSendAndConfirm = signSendAndConfirm;
|
|
239
260
|
const sendNativeToken = async (walletClient, publicClient, to, amount, confirmations = 1) => {
|
|
240
261
|
const value = typeof amount === 'string' ? (0, viem_1.parseEther)(amount) : amount;
|
|
241
|
-
return (0, exports.
|
|
262
|
+
return (0, exports.signAndSend)(walletClient, publicClient, { to, value }, confirmations);
|
|
242
263
|
};
|
|
243
264
|
exports.sendNativeToken = sendNativeToken;
|
|
244
265
|
const sendERC20Token = async (walletClient, publicClient, tokenAddress, to, amount, confirmations = 1) => {
|
|
@@ -247,7 +268,7 @@ const sendERC20Token = async (walletClient, publicClient, tokenAddress, to, amou
|
|
|
247
268
|
functionName: 'transfer',
|
|
248
269
|
args: [to, amount],
|
|
249
270
|
});
|
|
250
|
-
return (0, exports.
|
|
271
|
+
return (0, exports.signAndSend)(walletClient, publicClient, { to: tokenAddress, data }, confirmations);
|
|
251
272
|
};
|
|
252
273
|
exports.sendERC20Token = sendERC20Token;
|
|
253
274
|
const getGasPrices = async (client) => {
|
package/dist/test.js
CHANGED
|
@@ -59,6 +59,16 @@ const OgChainConfig = {
|
|
|
59
59
|
vmType: "EVM",
|
|
60
60
|
logoUrl: ""
|
|
61
61
|
};
|
|
62
|
+
const ethereumChainConfig = {
|
|
63
|
+
chainId: chains_1.mainnet.id,
|
|
64
|
+
name: chains_1.mainnet.name,
|
|
65
|
+
rpcUrl: chains_1.mainnet.rpcUrls.default.http[0],
|
|
66
|
+
explorerUrl: "",
|
|
67
|
+
nativeToken: chains_1.mainnet.nativeCurrency,
|
|
68
|
+
confirmationNo: 1,
|
|
69
|
+
vmType: "EVM",
|
|
70
|
+
logoUrl: ""
|
|
71
|
+
};
|
|
62
72
|
const wallet = new evm_1.EVMChainWallet(evmChainConfig, evmPrivateKeyExposed, 0);
|
|
63
73
|
const walletA = new evm_1.EVMChainWallet(evmChainConfig, evmPrivateKeyExposed, 0);
|
|
64
74
|
const walletB = new evm_1.EVMChainWallet(evmChainConfig, evmPrivKey, 0);
|
|
@@ -164,8 +174,11 @@ const testSavingsPocketSVM = async () => {
|
|
|
164
174
|
};
|
|
165
175
|
const testSavingsPocketMultiChain = async () => {
|
|
166
176
|
console.log('\n========== Multi-Chain Savings Test ==========');
|
|
167
|
-
const mnemonic =
|
|
168
|
-
|
|
177
|
+
const mnemonic = "exit alert stove save pair brass toss scheme shuffle loan gadget lunch";
|
|
178
|
+
const vm = new evm_1.EVMVM(evm_1.EVMVM.mnemonicToSeed(mnemonic));
|
|
179
|
+
const index = 1;
|
|
180
|
+
const wallet = new evm_1.EVMChainWallet(ethereumChainConfig, vm.generatePrivateKey(index).privateKey, index);
|
|
181
|
+
return;
|
|
169
182
|
const multiChainManager = new savings_1.MultiChainSavingsManager(mnemonic, [
|
|
170
183
|
{
|
|
171
184
|
id: 'base',
|
|
@@ -173,7 +186,7 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
173
186
|
config: evmChainConfig
|
|
174
187
|
},
|
|
175
188
|
{
|
|
176
|
-
id: '
|
|
189
|
+
id: '1',
|
|
177
190
|
type: 'EVM',
|
|
178
191
|
config: {
|
|
179
192
|
chainId: 1,
|
|
@@ -193,6 +206,8 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
193
206
|
}
|
|
194
207
|
}
|
|
195
208
|
], 0);
|
|
209
|
+
console.log('main wallet address', multiChainManager.getMainWalletAddress("1"));
|
|
210
|
+
return;
|
|
196
211
|
console.log('\nAvailable chains:', multiChainManager.getChains());
|
|
197
212
|
console.log('EVM chains:', multiChainManager.getEVMChains());
|
|
198
213
|
console.log('SVM chains:', multiChainManager.getSVMChains());
|
|
@@ -207,32 +222,11 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
207
222
|
console.log(' Base === Ethereum?', baseAddress === ethAddress, 'ā
');
|
|
208
223
|
console.log(' Base === Solana?', baseAddress === solAddress, 'ā (different chain type)');
|
|
209
224
|
console.log('\nš Getting balances across all chains...');
|
|
210
|
-
try {
|
|
211
|
-
const balances = await multiChainManager.getPocketBalanceAcrossChains(0, new Map([
|
|
212
|
-
['base', []],
|
|
213
|
-
['ethereum', []],
|
|
214
|
-
['solana', []]
|
|
215
|
-
]));
|
|
216
|
-
console.log('\nBalances for Pocket 0:');
|
|
217
|
-
balances.forEach(chainBalance => {
|
|
218
|
-
console.log(`\n ${chainBalance.chainId.toUpperCase()} (${chainBalance.chainType}):`);
|
|
219
|
-
console.log(` Address: ${chainBalance.address}`);
|
|
220
|
-
chainBalance.balances.forEach(bal => {
|
|
221
|
-
const tokenName = bal.token === 'native' ? 'Native' : bal.token;
|
|
222
|
-
console.log(` ${tokenName}: ${bal.balance.formatted}`);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
console.log(' ā ļø Balance fetch error (expected for demo RPCs):', error.message);
|
|
228
|
-
}
|
|
229
225
|
console.log('\nš§ Advanced: Direct chain manager access');
|
|
230
226
|
const baseManager = multiChainManager.getEVMManager('base');
|
|
231
227
|
const solanaManager = multiChainManager.getSVMManager('solana');
|
|
232
228
|
console.log(' Base manager type:', baseManager.constructor.name);
|
|
233
229
|
console.log(' Solana manager type:', solanaManager.constructor.name);
|
|
234
|
-
multiChainManager.dispose();
|
|
235
|
-
console.log('\nā
Multi-Chain Savings Test Complete\n');
|
|
236
230
|
};
|
|
237
231
|
const testEntropy = () => {
|
|
238
232
|
const p = evm_1.EVMVM.convertFromEntropyToPrivateKey("thishgbmytesentropystringis32bytes!hjkjkhknkjtdyftgkh,jryctdrfygh");
|
|
@@ -246,6 +240,6 @@ const testAddressClass = async () => {
|
|
|
246
240
|
console.log('res: ', res);
|
|
247
241
|
svm_1.SVMVM.generateMnemonicFromPrivateKey;
|
|
248
242
|
};
|
|
249
|
-
|
|
243
|
+
testSavingsPocketMultiChain();
|
|
250
244
|
const RPC_URL = chainConfig.rpcUrl;
|
|
251
245
|
const connection = new web3_js_1.Connection(RPC_URL);
|
package/package.json
CHANGED
package/utils/constant.ts
CHANGED
|
@@ -33,25 +33,25 @@ export const DefaultChains: ChainWalletConfig[] = [{
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
,
|
|
37
|
-
{
|
|
38
|
-
chainId: 42101,
|
|
39
|
-
name: "Push Chain Donut Testnet",
|
|
40
|
-
rpcUrl: "https://evm.donut.rpc.push.org",
|
|
41
|
-
explorerUrl: "https://donut.push.network",
|
|
42
|
-
nativeToken: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
testnet: true,
|
|
48
|
-
logoUrl: "https://push.org/assets/website/favicons/favicon.svg",
|
|
49
|
-
vmType: "EVM",
|
|
50
|
-
savings: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
36
|
+
// ,
|
|
37
|
+
// {
|
|
38
|
+
// chainId: 42101,
|
|
39
|
+
// name: "Push Chain Donut Testnet",
|
|
40
|
+
// rpcUrl: "https://evm.donut.rpc.push.org",
|
|
41
|
+
// explorerUrl: "https://donut.push.network",
|
|
42
|
+
// nativeToken: {
|
|
43
|
+
// name: "PC",
|
|
44
|
+
// symbol: "PC",
|
|
45
|
+
// decimals: 18,
|
|
46
|
+
// },
|
|
47
|
+
// testnet: true,
|
|
48
|
+
// logoUrl: "https://push.org/assets/website/favicons/favicon.svg",
|
|
49
|
+
// vmType: "EVM",
|
|
50
|
+
// savings: {
|
|
51
|
+
// supported: false,
|
|
52
|
+
// tokens: []
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
|
|
@@ -193,25 +193,8 @@ export const DefaultChains: ChainWalletConfig[] = [{
|
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
195
|
|
|
196
|
-
//add for polygon
|
|
197
|
-
|
|
198
|
-
chainId: 137,
|
|
199
|
-
name: "Polygon",
|
|
200
|
-
rpcUrl: "https://polygon-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
|
|
201
|
-
explorerUrl: "https://polygonscan.com",
|
|
202
|
-
nativeToken: {
|
|
203
|
-
name: "MATIC",
|
|
204
|
-
symbol: "MATIC",
|
|
205
|
-
decimals: 18,
|
|
206
|
-
},
|
|
207
|
-
testnet: false,
|
|
208
|
-
logoUrl: "https://polygonscan.com/images/svg/brands/polygon-light.svg?v=0.0.36",
|
|
209
|
-
vmType: "EVM",
|
|
210
|
-
savings: {
|
|
211
|
-
supported: false,
|
|
212
|
-
tokens: []
|
|
213
|
-
}
|
|
214
|
-
}
|
|
196
|
+
//add for polygon
|
|
197
|
+
|
|
215
198
|
|
|
216
199
|
|
|
217
200
|
]
|
package/utils/evm/utils.ts
CHANGED
|
@@ -357,6 +357,47 @@ export const getTokenBalance = async (
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Sign, send, and confirm any EVM transaction
|
|
362
|
+
*/
|
|
363
|
+
export const signAndSend = async (
|
|
364
|
+
walletClient: WalletClient,
|
|
365
|
+
publicClient: PublicClient,
|
|
366
|
+
params: {
|
|
367
|
+
to: Hex
|
|
368
|
+
data?: Hex
|
|
369
|
+
value?: bigint
|
|
370
|
+
gas?: bigint
|
|
371
|
+
nonce?: number
|
|
372
|
+
maxFeePerGas?: bigint
|
|
373
|
+
maxPriorityFeePerGas?: bigint
|
|
374
|
+
},
|
|
375
|
+
confirmations = 1
|
|
376
|
+
): Promise<{ hash: Hex, success: boolean }> => {
|
|
377
|
+
|
|
378
|
+
if (walletClient.account === undefined) {
|
|
379
|
+
throw new Error("wallet Client is not Initialized with an Account")
|
|
380
|
+
}
|
|
381
|
+
const hash = await walletClient.sendTransaction({
|
|
382
|
+
to: params.to,
|
|
383
|
+
data: params.data,
|
|
384
|
+
value: params.value,
|
|
385
|
+
gas: params.gas,
|
|
386
|
+
nonce: params.nonce,
|
|
387
|
+
maxFeePerGas: params.maxFeePerGas,
|
|
388
|
+
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
389
|
+
account: walletClient.account,
|
|
390
|
+
chain: publicClient.chain,
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
hash,
|
|
397
|
+
success: !!hash,
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
360
401
|
|
|
361
402
|
/**
|
|
362
403
|
* Sign, send, and confirm any EVM transaction
|
|
@@ -388,7 +429,8 @@ export const signSendAndConfirm = async (
|
|
|
388
429
|
maxFeePerGas: params.maxFeePerGas,
|
|
389
430
|
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
390
431
|
account: walletClient.account,
|
|
391
|
-
chain: publicClient.chain
|
|
432
|
+
chain: publicClient.chain,
|
|
433
|
+
|
|
392
434
|
|
|
393
435
|
})
|
|
394
436
|
|
|
@@ -423,7 +465,7 @@ export const sendNativeToken = async (
|
|
|
423
465
|
const value =
|
|
424
466
|
typeof amount === 'string' ? parseEther(amount) : amount
|
|
425
467
|
|
|
426
|
-
return
|
|
468
|
+
return signAndSend(
|
|
427
469
|
walletClient,
|
|
428
470
|
publicClient,
|
|
429
471
|
{ to, value },
|
|
@@ -449,7 +491,7 @@ export const sendERC20Token = async (
|
|
|
449
491
|
args: [to, amount],
|
|
450
492
|
})
|
|
451
493
|
|
|
452
|
-
return
|
|
494
|
+
return signAndSend(
|
|
453
495
|
walletClient,
|
|
454
496
|
publicClient,
|
|
455
497
|
{ to: tokenAddress, data },
|
package/utils/test.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { discoverNFTs, EVMChainAddress, EVMChainWallet, EVMVM } from "./evm";
|
|
|
12
12
|
import { } from "./svm/transactionParsing";
|
|
13
13
|
import { getEVMTransactionHistory } from "./evm/transactionParsing";
|
|
14
14
|
import { createPublicClient, encodeFunctionData, Hex, http, parseAbi, parseUnits, PublicClient, zeroAddress } from "viem";
|
|
15
|
-
import { base, baseGoerli } from "viem/chains";
|
|
15
|
+
import { base, baseGoerli, mainnet } from "viem/chains";
|
|
16
16
|
import { discoverTokens, fetchWalletNfts, getTokenInfo } from "./svm/utils";
|
|
17
17
|
import { JsonRpcProvider, N } from "ethers";
|
|
18
18
|
|
|
@@ -96,7 +96,17 @@ const OgChainConfig: ChainWalletConfig = {
|
|
|
96
96
|
logoUrl: ""
|
|
97
97
|
|
|
98
98
|
}
|
|
99
|
+
const ethereumChainConfig: ChainWalletConfig = {
|
|
100
|
+
chainId: mainnet.id,
|
|
101
|
+
name: mainnet.name,
|
|
102
|
+
rpcUrl: mainnet.rpcUrls.default.http[0],
|
|
103
|
+
explorerUrl: "",
|
|
104
|
+
nativeToken: mainnet.nativeCurrency,
|
|
105
|
+
confirmationNo: 1,
|
|
106
|
+
vmType: "EVM",
|
|
107
|
+
logoUrl: ""
|
|
99
108
|
|
|
109
|
+
}
|
|
100
110
|
|
|
101
111
|
// const wallet = new SVMChainWallet(chainConfig, testUserKeyPair, 0)
|
|
102
112
|
const wallet = new EVMChainWallet(evmChainConfig, evmPrivateKeyExposed, 0)
|
|
@@ -295,8 +305,16 @@ const testSavingsPocketSVM = async () => {
|
|
|
295
305
|
// ============================================
|
|
296
306
|
const testSavingsPocketMultiChain = async () => {
|
|
297
307
|
console.log('\n========== Multi-Chain Savings Test ==========');
|
|
298
|
-
const mnemonic =
|
|
299
|
-
|
|
308
|
+
const mnemonic = "exit alert stove save pair brass toss scheme shuffle loan gadget lunch"
|
|
309
|
+
const vm = new EVMVM(EVMVM.mnemonicToSeed(mnemonic))
|
|
310
|
+
const index = 1
|
|
311
|
+
const wallet = new EVMChainWallet(
|
|
312
|
+
ethereumChainConfig
|
|
313
|
+
, vm.generatePrivateKey(index).privateKey, index)
|
|
314
|
+
|
|
315
|
+
// const result = wallet.transferToken()
|
|
316
|
+
|
|
317
|
+
return
|
|
300
318
|
|
|
301
319
|
// Create multi-chain manager with EVM and Solana
|
|
302
320
|
const multiChainManager = new MultiChainSavingsManager(
|
|
@@ -308,7 +326,7 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
308
326
|
config: evmChainConfig
|
|
309
327
|
},
|
|
310
328
|
{
|
|
311
|
-
id: '
|
|
329
|
+
id: '1',
|
|
312
330
|
type: 'EVM',
|
|
313
331
|
config: {
|
|
314
332
|
chainId: 1,
|
|
@@ -331,6 +349,8 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
331
349
|
0 // wallet index
|
|
332
350
|
);
|
|
333
351
|
|
|
352
|
+
console.log('main wallet address', multiChainManager.getMainWalletAddress("1"));
|
|
353
|
+
return
|
|
334
354
|
console.log('\nAvailable chains:', multiChainManager.getChains());
|
|
335
355
|
console.log('EVM chains:', multiChainManager.getEVMChains());
|
|
336
356
|
console.log('SVM chains:', multiChainManager.getSVMChains());
|
|
@@ -352,28 +372,28 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
352
372
|
|
|
353
373
|
// Get balances across chains
|
|
354
374
|
console.log('\nš Getting balances across all chains...');
|
|
355
|
-
try {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
} catch (error) {
|
|
375
|
-
|
|
376
|
-
}
|
|
375
|
+
// try {
|
|
376
|
+
// const balances = await multiChainManager.getPocketBalanceAcrossChains(
|
|
377
|
+
// 0, // pocket index
|
|
378
|
+
// new Map([
|
|
379
|
+
// ['base', []], // No tokens, just native
|
|
380
|
+
// ['ethereum', []],
|
|
381
|
+
// ['solana', []]
|
|
382
|
+
// ])
|
|
383
|
+
// );
|
|
384
|
+
|
|
385
|
+
// console.log('\nBalances for Pocket 0:');
|
|
386
|
+
// balances.forEach(chainBalance => {
|
|
387
|
+
// console.log(`\n ${chainBalance.chainId.toUpperCase()} (${chainBalance.chainType}):`);
|
|
388
|
+
// console.log(` Address: ${chainBalance.address}`);
|
|
389
|
+
// chainBalance.balances.forEach(bal => {
|
|
390
|
+
// const tokenName = bal.token === 'native' ? 'Native' : bal.token;
|
|
391
|
+
// console.log(` ${tokenName}: ${bal.balance.formatted}`);
|
|
392
|
+
// });
|
|
393
|
+
// });
|
|
394
|
+
// } catch (error) {
|
|
395
|
+
// console.log(' ā ļø Balance fetch error (expected for demo RPCs):', (error as Error).message);
|
|
396
|
+
// }
|
|
377
397
|
|
|
378
398
|
// Get specific chain managers for advanced operations
|
|
379
399
|
console.log('\nš§ Advanced: Direct chain manager access');
|
|
@@ -382,9 +402,7 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
382
402
|
console.log(' Base manager type:', baseManager.constructor.name);
|
|
383
403
|
console.log(' Solana manager type:', solanaManager.constructor.name);
|
|
384
404
|
|
|
385
|
-
|
|
386
|
-
multiChainManager.dispose();
|
|
387
|
-
console.log('\nā
Multi-Chain Savings Test Complete\n');
|
|
405
|
+
|
|
388
406
|
}
|
|
389
407
|
|
|
390
408
|
const testEntropy = () => {
|
|
@@ -399,10 +417,10 @@ const testAddressClass = async () => {
|
|
|
399
417
|
const evmAddressClass = new EVMChainAddress(evmChainConfig, "0xC9C1D854b82BA9b4FB6f6D58E9EF3d1fAEd601AA", 0)
|
|
400
418
|
const res = await evmAddressClass.getNativeBalance()
|
|
401
419
|
console.log('res: ', res);
|
|
402
|
-
SVMVM.generateMnemonicFromPrivateKey
|
|
420
|
+
SVMVM.generateMnemonicFromPrivateKey
|
|
403
421
|
// const svmAddressClass = new SVMChainAddress( )
|
|
404
422
|
}
|
|
405
|
-
|
|
423
|
+
testSavingsPocketMultiChain()
|
|
406
424
|
// Uncomment to run tests
|
|
407
425
|
// testSavingsPocket()
|
|
408
426
|
// testSavingsPocketSVM()
|