@deserialize/multi-vm-wallet 1.5.11 → 1.5.21

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.
@@ -1 +1,9 @@
1
- export * from "./saving-manager";
1
+ export * from "./savings-manager";
2
+ export * from "./evm-savings";
3
+ export * from "./svm-savings";
4
+ export * from "./multi-chain-savings";
5
+ export * from "./types";
6
+ export * from "./validation";
7
+ export { BaseSavingsManager as LegacyBaseSavingsManager, SavingsManager as LegacySavingsManager } from "./saving-manager";
8
+ export * from "./smart-savings";
9
+ export * from "./savings-operations";
@@ -14,4 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./saving-manager"), exports);
17
+ exports.LegacySavingsManager = exports.LegacyBaseSavingsManager = void 0;
18
+ __exportStar(require("./savings-manager"), exports);
19
+ __exportStar(require("./evm-savings"), exports);
20
+ __exportStar(require("./svm-savings"), exports);
21
+ __exportStar(require("./multi-chain-savings"), exports);
22
+ __exportStar(require("./types"), exports);
23
+ __exportStar(require("./validation"), exports);
24
+ var saving_manager_1 = require("./saving-manager");
25
+ Object.defineProperty(exports, "LegacyBaseSavingsManager", { enumerable: true, get: function () { return saving_manager_1.BaseSavingsManager; } });
26
+ Object.defineProperty(exports, "LegacySavingsManager", { enumerable: true, get: function () { return saving_manager_1.SavingsManager; } });
27
+ __exportStar(require("./smart-savings"), exports);
28
+ __exportStar(require("./savings-operations"), exports);
@@ -0,0 +1,48 @@
1
+ import { EVMSavingsManager } from "./evm-savings";
2
+ import { SVMSavingsManager } from "./svm-savings";
3
+ import { ChainWalletConfig, Balance } from "../types";
4
+ export type ChainType = 'EVM' | 'SVM';
5
+ export interface ChainConfig {
6
+ id: string;
7
+ type: ChainType;
8
+ config: ChainWalletConfig | {
9
+ rpcUrl: string;
10
+ };
11
+ }
12
+ export interface PocketBalance {
13
+ chainId: string;
14
+ chainType: ChainType;
15
+ pocketIndex: number;
16
+ address: string;
17
+ balances: {
18
+ token: string;
19
+ balance: Balance;
20
+ }[];
21
+ }
22
+ export declare class MultiChainSavingsManager {
23
+ private mnemonic;
24
+ private walletIndex;
25
+ private evmManagers;
26
+ private svmManagers;
27
+ private chainConfigs;
28
+ constructor(mnemonic: string, chains: ChainConfig[], walletIndex?: number);
29
+ addChain(chain: ChainConfig): void;
30
+ removeChain(chainId: string): void;
31
+ getChains(): string[];
32
+ getChainConfig(chainId: string): ChainConfig;
33
+ getPocketAddress(chainId: string, pocketIndex: number): string;
34
+ getMainWalletAddress(chainId: string): string;
35
+ getPocketBalance(chainId: string, pocketIndex: number, tokens: string[]): Promise<PocketBalance>;
36
+ getPocketBalanceAcrossChains(pocketIndex: number, tokensByChain: Map<string, string[]>): Promise<PocketBalance[]>;
37
+ getAllPocketsBalanceAcrossChains(pocketIndices: number[], tokensByChain: Map<string, string[]>): Promise<Map<number, PocketBalance[]>>;
38
+ getEVMManager(chainId: string): EVMSavingsManager;
39
+ getSVMManager(chainId: string): SVMSavingsManager;
40
+ isEVMChain(chainId: string): boolean;
41
+ isSVMChain(chainId: string): boolean;
42
+ getEVMChains(): string[];
43
+ getSVMChains(): string[];
44
+ clearPocket(pocketIndex: number): void;
45
+ clearAllPockets(): void;
46
+ clearAllClients(): void;
47
+ dispose(): void;
48
+ }
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiChainSavingsManager = void 0;
4
+ const evm_savings_1 = require("./evm-savings");
5
+ const svm_savings_1 = require("./svm-savings");
6
+ class MultiChainSavingsManager {
7
+ mnemonic;
8
+ walletIndex;
9
+ evmManagers = new Map();
10
+ svmManagers = new Map();
11
+ chainConfigs = new Map();
12
+ constructor(mnemonic, chains, walletIndex = 0) {
13
+ if (!mnemonic || typeof mnemonic !== 'string') {
14
+ throw new Error('Mnemonic must be a non-empty string');
15
+ }
16
+ if (!Array.isArray(chains) || chains.length === 0) {
17
+ throw new Error('Chains array must be non-empty');
18
+ }
19
+ this.mnemonic = mnemonic;
20
+ this.walletIndex = walletIndex;
21
+ for (const chain of chains) {
22
+ this.addChain(chain);
23
+ }
24
+ }
25
+ addChain(chain) {
26
+ if (!chain.id || !chain.type) {
27
+ throw new Error('Chain must have id and type');
28
+ }
29
+ if (this.chainConfigs.has(chain.id)) {
30
+ throw new Error(`Chain with id '${chain.id}' already exists`);
31
+ }
32
+ this.chainConfigs.set(chain.id, chain);
33
+ if (chain.type === 'EVM') {
34
+ const manager = new evm_savings_1.EVMSavingsManager(this.mnemonic, chain.config, this.walletIndex);
35
+ this.evmManagers.set(chain.id, manager);
36
+ }
37
+ else if (chain.type === 'SVM') {
38
+ const config = chain.config;
39
+ if (!config.rpcUrl) {
40
+ throw new Error(`SVM chain '${chain.id}' must have rpcUrl in config`);
41
+ }
42
+ const manager = new svm_savings_1.SVMSavingsManager(this.mnemonic, config.rpcUrl, this.walletIndex);
43
+ this.svmManagers.set(chain.id, manager);
44
+ }
45
+ else {
46
+ throw new Error(`Unknown chain type: ${chain.type}`);
47
+ }
48
+ }
49
+ removeChain(chainId) {
50
+ if (this.evmManagers.has(chainId)) {
51
+ this.evmManagers.get(chainId)?.dispose();
52
+ this.evmManagers.delete(chainId);
53
+ }
54
+ if (this.svmManagers.has(chainId)) {
55
+ this.svmManagers.get(chainId)?.dispose();
56
+ this.svmManagers.delete(chainId);
57
+ }
58
+ this.chainConfigs.delete(chainId);
59
+ }
60
+ getChains() {
61
+ return Array.from(this.chainConfigs.keys());
62
+ }
63
+ getChainConfig(chainId) {
64
+ const config = this.chainConfigs.get(chainId);
65
+ if (!config) {
66
+ throw new Error(`Chain not found: ${chainId}`);
67
+ }
68
+ return config;
69
+ }
70
+ getPocketAddress(chainId, pocketIndex) {
71
+ const chain = this.getChainConfig(chainId);
72
+ if (chain.type === 'EVM') {
73
+ const manager = this.evmManagers.get(chainId);
74
+ return manager.getPocket(pocketIndex).address;
75
+ }
76
+ else {
77
+ const manager = this.svmManagers.get(chainId);
78
+ return manager.getPocket(pocketIndex).address.toBase58();
79
+ }
80
+ }
81
+ getMainWalletAddress(chainId) {
82
+ const chain = this.getChainConfig(chainId);
83
+ if (chain.type === 'EVM') {
84
+ const manager = this.evmManagers.get(chainId);
85
+ return manager.getMainWalletAddress();
86
+ }
87
+ else {
88
+ const manager = this.svmManagers.get(chainId);
89
+ return manager.getMainWalletAddress().toBase58();
90
+ }
91
+ }
92
+ async getPocketBalance(chainId, pocketIndex, tokens) {
93
+ const chain = this.getChainConfig(chainId);
94
+ if (chain.type === 'EVM') {
95
+ const manager = this.evmManagers.get(chainId);
96
+ const balances = await manager.getPocketBalance(pocketIndex, tokens);
97
+ const pocket = manager.getPocket(pocketIndex);
98
+ return {
99
+ chainId,
100
+ chainType: 'EVM',
101
+ pocketIndex,
102
+ address: pocket.address,
103
+ balances: balances.map(b => ({
104
+ token: b.address === 'native' ? 'native' : b.address,
105
+ balance: b.balance
106
+ }))
107
+ };
108
+ }
109
+ else {
110
+ const manager = this.svmManagers.get(chainId);
111
+ const balances = await manager.getPocketBalance(pocketIndex, tokens);
112
+ const pocket = manager.getPocket(pocketIndex);
113
+ return {
114
+ chainId,
115
+ chainType: 'SVM',
116
+ pocketIndex,
117
+ address: pocket.address.toBase58(),
118
+ balances: balances.map(b => ({
119
+ token: b.address === 'native' ? 'native' : b.address.toBase58(),
120
+ balance: b.balance
121
+ }))
122
+ };
123
+ }
124
+ }
125
+ async getPocketBalanceAcrossChains(pocketIndex, tokensByChain) {
126
+ const promises = [];
127
+ for (const [chainId, tokens] of tokensByChain) {
128
+ promises.push(this.getPocketBalance(chainId, pocketIndex, tokens));
129
+ }
130
+ return await Promise.all(promises);
131
+ }
132
+ async getAllPocketsBalanceAcrossChains(pocketIndices, tokensByChain) {
133
+ const results = new Map();
134
+ await Promise.all(pocketIndices.map(async (pocketIndex) => {
135
+ const balances = await this.getPocketBalanceAcrossChains(pocketIndex, tokensByChain);
136
+ results.set(pocketIndex, balances);
137
+ }));
138
+ return results;
139
+ }
140
+ getEVMManager(chainId) {
141
+ const manager = this.evmManagers.get(chainId);
142
+ if (!manager) {
143
+ throw new Error(`EVM chain not found: ${chainId}`);
144
+ }
145
+ return manager;
146
+ }
147
+ getSVMManager(chainId) {
148
+ const manager = this.svmManagers.get(chainId);
149
+ if (!manager) {
150
+ throw new Error(`SVM chain not found: ${chainId}`);
151
+ }
152
+ return manager;
153
+ }
154
+ isEVMChain(chainId) {
155
+ return this.evmManagers.has(chainId);
156
+ }
157
+ isSVMChain(chainId) {
158
+ return this.svmManagers.has(chainId);
159
+ }
160
+ getEVMChains() {
161
+ return Array.from(this.evmManagers.keys());
162
+ }
163
+ getSVMChains() {
164
+ return Array.from(this.svmManagers.keys());
165
+ }
166
+ clearPocket(pocketIndex) {
167
+ for (const manager of this.evmManagers.values()) {
168
+ manager.clearPocket(pocketIndex);
169
+ }
170
+ for (const manager of this.svmManagers.values()) {
171
+ manager.clearPocket(pocketIndex);
172
+ }
173
+ }
174
+ clearAllPockets() {
175
+ for (const manager of this.evmManagers.values()) {
176
+ manager.clearAllPockets();
177
+ }
178
+ for (const manager of this.svmManagers.values()) {
179
+ manager.clearAllPockets();
180
+ }
181
+ }
182
+ clearAllClients() {
183
+ for (const manager of this.evmManagers.values()) {
184
+ manager.clearClient();
185
+ }
186
+ for (const manager of this.svmManagers.values()) {
187
+ manager.clearClient();
188
+ }
189
+ }
190
+ dispose() {
191
+ for (const manager of this.evmManagers.values()) {
192
+ manager.dispose();
193
+ }
194
+ for (const manager of this.svmManagers.values()) {
195
+ manager.dispose();
196
+ }
197
+ this.evmManagers.clear();
198
+ this.svmManagers.clear();
199
+ this.chainConfigs.clear();
200
+ this.mnemonic = '';
201
+ }
202
+ }
203
+ exports.MultiChainSavingsManager = MultiChainSavingsManager;
@@ -0,0 +1,28 @@
1
+ export interface Pocket<AddressType> {
2
+ privateKey: any;
3
+ address: AddressType;
4
+ derivationPath: string;
5
+ index: number;
6
+ }
7
+ export declare abstract class SavingsManager<AddressType, ClientType, WalletClientType> {
8
+ protected mnemonic: string;
9
+ protected walletIndex: number;
10
+ protected disposed: boolean;
11
+ abstract coinType: number;
12
+ abstract derivationPathBase: string;
13
+ protected pockets: Map<number, Pocket<AddressType>>;
14
+ constructor(mnemonic: string, walletIndex?: number);
15
+ abstract derivePocket(accountIndex: number): Pocket<AddressType>;
16
+ abstract getMainWallet(): {
17
+ privateKey: any;
18
+ address: AddressType;
19
+ derivationPath: string;
20
+ };
21
+ abstract createClient(rpcUrl: string): ClientType;
22
+ getPocket(accountIndex: number): Pocket<AddressType>;
23
+ clearPocket(accountIndex: number): void;
24
+ clearAllPockets(): void;
25
+ dispose(): void;
26
+ isDisposed(): boolean;
27
+ protected checkNotDisposed(): void;
28
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SavingsManager = void 0;
4
+ const validation_1 = require("./validation");
5
+ class SavingsManager {
6
+ mnemonic;
7
+ walletIndex;
8
+ disposed = false;
9
+ pockets = new Map();
10
+ constructor(mnemonic, walletIndex = 0) {
11
+ validation_1.SavingsValidation.validateMnemonic(mnemonic);
12
+ validation_1.SavingsValidation.validateWalletIndex(walletIndex);
13
+ this.mnemonic = mnemonic;
14
+ this.walletIndex = walletIndex;
15
+ }
16
+ getPocket(accountIndex) {
17
+ this.checkNotDisposed();
18
+ validation_1.SavingsValidation.validateAccountIndex(accountIndex);
19
+ if (!this.pockets.has(accountIndex)) {
20
+ return this.derivePocket(accountIndex);
21
+ }
22
+ return this.pockets.get(accountIndex);
23
+ }
24
+ clearPocket(accountIndex) {
25
+ validation_1.SavingsValidation.validateAccountIndex(accountIndex);
26
+ if (this.pockets.has(accountIndex)) {
27
+ const pocket = this.pockets.get(accountIndex);
28
+ pocket.privateKey = '';
29
+ this.pockets.delete(accountIndex);
30
+ }
31
+ }
32
+ clearAllPockets() {
33
+ for (const [_, pocket] of this.pockets.entries()) {
34
+ pocket.privateKey = '';
35
+ }
36
+ this.pockets.clear();
37
+ }
38
+ dispose() {
39
+ if (this.disposed) {
40
+ return;
41
+ }
42
+ this.clearAllPockets();
43
+ this.mnemonic = '';
44
+ this.disposed = true;
45
+ }
46
+ isDisposed() {
47
+ return this.disposed || !this.mnemonic || this.mnemonic === '';
48
+ }
49
+ checkNotDisposed() {
50
+ if (this.isDisposed()) {
51
+ throw new Error('SavingsManager has been disposed. Create a new instance to perform operations.');
52
+ }
53
+ }
54
+ }
55
+ exports.SavingsManager = SavingsManager;
@@ -0,0 +1,40 @@
1
+ import { SavingsManager, Pocket } from "./savings-manager";
2
+ import { Connection, PublicKey, Keypair } from "@solana/web3.js";
3
+ import { Balance, TransactionResult } from "../types";
4
+ export declare class SVMSavingsManager extends SavingsManager<PublicKey, Connection, Keypair> {
5
+ coinType: number;
6
+ derivationPathBase: string;
7
+ private rpcUrl;
8
+ private _client?;
9
+ constructor(mnemonic: string, rpcUrl: string, walletIndex?: number);
10
+ get client(): Connection;
11
+ createClient(rpcUrl: string): Connection;
12
+ clearClient(): void;
13
+ derivePocket(accountIndex: number): Pocket<PublicKey>;
14
+ getMainWallet(): {
15
+ privateKey: Keypair;
16
+ address: PublicKey;
17
+ derivationPath: string;
18
+ };
19
+ getMainWalletAddress(): PublicKey;
20
+ getPocketBalance(pocketIndex: number, tokens: string[]): Promise<{
21
+ address: PublicKey | 'native';
22
+ balance: Balance;
23
+ }[]>;
24
+ getTotalTokenBalanceOfAllPockets(tokens: string[], pockets: number[]): Promise<Array<{
25
+ address: PublicKey | 'native';
26
+ balance: Balance;
27
+ }[]>>;
28
+ transferToPocket(mainWallet: Keypair, pocketIndex: number, amount: bigint): Promise<TransactionResult>;
29
+ transferTokenToPocket(mainWallet: Keypair, tokenInfo: {
30
+ address: string;
31
+ decimals: number;
32
+ }, pocketIndex: number, amount: bigint): Promise<TransactionResult>;
33
+ accountFromPocketId(pocketIndex: number): Keypair;
34
+ verifyPocketAddress(accountIndex: number, storedAddress: string): boolean;
35
+ sendToMainWallet(pocketIndex: number, amount: bigint, token: {
36
+ address: string;
37
+ decimals: number;
38
+ } | "native"): Promise<TransactionResult>;
39
+ dispose(): void;
40
+ }
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SVMSavingsManager = void 0;
7
+ const savings_manager_1 = require("./savings-manager");
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const walletBip32_1 = require("../walletBip32");
10
+ const svm_1 = require("../svm");
11
+ const validation_1 = require("./validation");
12
+ const bn_js_1 = __importDefault(require("bn.js"));
13
+ class SVMSavingsManager extends savings_manager_1.SavingsManager {
14
+ coinType = 501;
15
+ derivationPathBase = "m/44'/501'/";
16
+ rpcUrl;
17
+ _client;
18
+ constructor(mnemonic, rpcUrl, walletIndex = 0) {
19
+ super(mnemonic, walletIndex);
20
+ if (!rpcUrl || typeof rpcUrl !== 'string') {
21
+ throw new Error('RPC URL must be a non-empty string');
22
+ }
23
+ this.rpcUrl = rpcUrl;
24
+ }
25
+ get client() {
26
+ if (!this._client) {
27
+ this._client = this.createClient(this.rpcUrl);
28
+ }
29
+ return this._client;
30
+ }
31
+ createClient(rpcUrl) {
32
+ return new web3_js_1.Connection(rpcUrl, 'confirmed');
33
+ }
34
+ clearClient() {
35
+ this._client = undefined;
36
+ }
37
+ derivePocket(accountIndex) {
38
+ this.checkNotDisposed();
39
+ validation_1.SavingsValidation.validateAccountIndex(accountIndex);
40
+ const pocketIndex = accountIndex + 1;
41
+ const derivationPath = `${this.derivationPathBase}${pocketIndex}'/0/${this.walletIndex}`;
42
+ const seed = (0, walletBip32_1.mnemonicToSeed)(this.mnemonic);
43
+ const keypair = (0, walletBip32_1.SVMDeriveChildPrivateKey)(seed, this.walletIndex, derivationPath);
44
+ const pocket = {
45
+ privateKey: keypair,
46
+ address: keypair.publicKey,
47
+ derivationPath,
48
+ index: pocketIndex
49
+ };
50
+ this.pockets.set(accountIndex, pocket);
51
+ return pocket;
52
+ }
53
+ getMainWallet() {
54
+ this.checkNotDisposed();
55
+ const derivationPath = `${this.derivationPathBase}0'/0/${this.walletIndex}`;
56
+ const seed = (0, walletBip32_1.mnemonicToSeed)(this.mnemonic);
57
+ const keypair = (0, walletBip32_1.SVMDeriveChildPrivateKey)(seed, this.walletIndex, derivationPath);
58
+ return {
59
+ privateKey: keypair,
60
+ address: keypair.publicKey,
61
+ derivationPath
62
+ };
63
+ }
64
+ getMainWalletAddress() {
65
+ return this.getMainWallet().address;
66
+ }
67
+ async getPocketBalance(pocketIndex, tokens) {
68
+ validation_1.SavingsValidation.validateAccountIndex(pocketIndex);
69
+ if (!Array.isArray(tokens)) {
70
+ throw new Error('Tokens must be an array');
71
+ }
72
+ const pocket = this.getPocket(pocketIndex);
73
+ const balances = [];
74
+ const nativeBalance = await (0, svm_1.getSvmNativeBalance)(pocket.address, this.client);
75
+ balances.push({ address: 'native', balance: nativeBalance });
76
+ await Promise.all(tokens.map(async (token) => {
77
+ try {
78
+ const tokenPubkey = new web3_js_1.PublicKey(token);
79
+ const tokenBalanceData = await (0, svm_1.getTokenBalance)(pocket.address, tokenPubkey, this.client);
80
+ if (tokenBalanceData === 0) {
81
+ balances.push({
82
+ address: tokenPubkey,
83
+ balance: { balance: new bn_js_1.default(0), formatted: 0, decimal: 0 }
84
+ });
85
+ }
86
+ else {
87
+ const balance = {
88
+ balance: new bn_js_1.default(tokenBalanceData.amount),
89
+ formatted: tokenBalanceData.uiAmount || 0,
90
+ decimal: tokenBalanceData.decimals
91
+ };
92
+ balances.push({ address: tokenPubkey, balance });
93
+ }
94
+ }
95
+ catch (error) {
96
+ balances.push({
97
+ address: new web3_js_1.PublicKey(token),
98
+ balance: { balance: new bn_js_1.default(0), formatted: 0, decimal: 0 }
99
+ });
100
+ }
101
+ }));
102
+ return balances;
103
+ }
104
+ async getTotalTokenBalanceOfAllPockets(tokens, pockets) {
105
+ if (!Array.isArray(tokens) || tokens.length === 0) {
106
+ throw new Error('Tokens array must be non-empty');
107
+ }
108
+ if (!Array.isArray(pockets) || pockets.length === 0) {
109
+ throw new Error('Pockets array must be non-empty');
110
+ }
111
+ pockets.forEach((pocket) => {
112
+ validation_1.SavingsValidation.validateAccountIndex(pocket);
113
+ });
114
+ const allBalances = await Promise.all(pockets.map((p) => this.getPocketBalance(p, tokens)));
115
+ return allBalances;
116
+ }
117
+ async transferToPocket(mainWallet, pocketIndex, amount) {
118
+ validation_1.SavingsValidation.validateAccountIndex(pocketIndex);
119
+ if (typeof amount !== 'bigint' || amount <= 0n) {
120
+ throw new Error(`Amount must be a positive bigint, got: ${amount}`);
121
+ }
122
+ const pocket = this.getPocket(pocketIndex);
123
+ const tx = await (0, svm_1.getTransferNativeTransaction)(mainWallet, pocket.address, Number(amount), this.client);
124
+ const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, mainWallet);
125
+ return { success: true, hash };
126
+ }
127
+ async transferTokenToPocket(mainWallet, tokenInfo, pocketIndex, amount) {
128
+ validation_1.SavingsValidation.validateAccountIndex(pocketIndex);
129
+ if (typeof amount !== 'bigint' || amount <= 0n) {
130
+ throw new Error(`Amount must be a positive bigint, got: ${amount}`);
131
+ }
132
+ const pocket = this.getPocket(pocketIndex);
133
+ const tx = await (0, svm_1.getTransferTokenTransaction)(mainWallet, pocket.address, tokenInfo, Number(amount), this.client);
134
+ const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, mainWallet);
135
+ return { success: true, hash };
136
+ }
137
+ accountFromPocketId(pocketIndex) {
138
+ const pocket = this.getPocket(pocketIndex);
139
+ return pocket.privateKey;
140
+ }
141
+ verifyPocketAddress(accountIndex, storedAddress) {
142
+ validation_1.SavingsValidation.validateAccountIndex(accountIndex);
143
+ if (!storedAddress || typeof storedAddress !== 'string') {
144
+ throw new Error('Stored address must be a non-empty string');
145
+ }
146
+ try {
147
+ const pocket = this.getPocket(accountIndex);
148
+ const storedPubkey = new web3_js_1.PublicKey(storedAddress);
149
+ return pocket.address.equals(storedPubkey);
150
+ }
151
+ catch (error) {
152
+ return false;
153
+ }
154
+ }
155
+ async sendToMainWallet(pocketIndex, amount, token) {
156
+ validation_1.SavingsValidation.validateAccountIndex(pocketIndex);
157
+ if (typeof amount !== 'bigint' || amount <= 0n) {
158
+ throw new Error(`Amount must be a positive bigint, got: ${amount}`);
159
+ }
160
+ const pocket = this.getPocket(pocketIndex);
161
+ const mainWalletAddress = this.getMainWalletAddress();
162
+ if (token === "native") {
163
+ const tx = await (0, svm_1.getTransferNativeTransaction)(pocket.privateKey, mainWalletAddress, Number(amount), this.client);
164
+ const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, pocket.privateKey);
165
+ return { success: true, hash };
166
+ }
167
+ const tx = await (0, svm_1.getTransferTokenTransaction)(pocket.privateKey, mainWalletAddress, token, Number(amount), this.client);
168
+ const hash = await (0, svm_1.signAndSendTransaction)(tx, this.client, pocket.privateKey);
169
+ return { success: true, hash };
170
+ }
171
+ dispose() {
172
+ super.dispose();
173
+ this.clearClient();
174
+ }
175
+ }
176
+ exports.SVMSavingsManager = SVMSavingsManager;
@@ -1 +1,2 @@
1
1
  export * from "./svm";
2
+ export * from "./utils";
package/dist/svm/index.js CHANGED
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./svm"), exports);
18
+ __exportStar(require("./utils"), exports);