@pushchain/core 0.1.0

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.
Files changed (81) hide show
  1. package/README.md +241 -0
  2. package/package.json +30 -0
  3. package/src/index.d.ts +1 -0
  4. package/src/index.js +5 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/constants/abi/factoryV1.d.ts +81 -0
  7. package/src/lib/constants/abi/factoryV1.js +255 -0
  8. package/src/lib/constants/abi/factoryV1.js.map +1 -0
  9. package/src/lib/constants/abi/feeLocker.evm.d.ts +39 -0
  10. package/src/lib/constants/abi/feeLocker.evm.js +319 -0
  11. package/src/lib/constants/abi/feeLocker.evm.js.map +1 -0
  12. package/src/lib/constants/abi/feeLocker.json +230 -0
  13. package/src/lib/constants/abi/index.d.ts +5 -0
  14. package/src/lib/constants/abi/index.js +15 -0
  15. package/src/lib/constants/abi/index.js.map +1 -0
  16. package/src/lib/constants/abi/smartAccount.evm.d.ts +110 -0
  17. package/src/lib/constants/abi/smartAccount.evm.js +212 -0
  18. package/src/lib/constants/abi/smartAccount.evm.js.map +1 -0
  19. package/src/lib/constants/abi/smartAccount.svm.d.ts +106 -0
  20. package/src/lib/constants/abi/smartAccount.svm.js +209 -0
  21. package/src/lib/constants/abi/smartAccount.svm.js.map +1 -0
  22. package/src/lib/constants/chain.d.ts +32 -0
  23. package/src/lib/constants/chain.js +79 -0
  24. package/src/lib/constants/chain.js.map +1 -0
  25. package/src/lib/constants/enums.d.ts +30 -0
  26. package/src/lib/constants/enums.js +40 -0
  27. package/src/lib/constants/enums.js.map +1 -0
  28. package/src/lib/constants/index.d.ts +5 -0
  29. package/src/lib/constants/index.js +10 -0
  30. package/src/lib/constants/index.js.map +1 -0
  31. package/src/lib/generated/v1/tx.d.ts +83 -0
  32. package/src/lib/generated/v1/tx.js +616 -0
  33. package/src/lib/generated/v1/tx.js.map +1 -0
  34. package/src/lib/index.d.ts +3 -0
  35. package/src/lib/index.js +8 -0
  36. package/src/lib/index.js.map +1 -0
  37. package/src/lib/orchestrator/orchestrator.d.ts +63 -0
  38. package/src/lib/orchestrator/orchestrator.js +475 -0
  39. package/src/lib/orchestrator/orchestrator.js.map +1 -0
  40. package/src/lib/orchestrator/orchestrator.types.d.ts +44 -0
  41. package/src/lib/orchestrator/orchestrator.types.js +3 -0
  42. package/src/lib/orchestrator/orchestrator.types.js.map +1 -0
  43. package/src/lib/price-fetch/price-fetch.d.ts +13 -0
  44. package/src/lib/price-fetch/price-fetch.js +115 -0
  45. package/src/lib/price-fetch/price-fetch.js.map +1 -0
  46. package/src/lib/push-client/push-client.d.ts +47 -0
  47. package/src/lib/push-client/push-client.js +132 -0
  48. package/src/lib/push-client/push-client.js.map +1 -0
  49. package/src/lib/push-client/push-client.types.d.ts +5 -0
  50. package/src/lib/push-client/push-client.types.js +3 -0
  51. package/src/lib/push-client/push-client.types.js.map +1 -0
  52. package/src/lib/pushChain.d.ts +50 -0
  53. package/src/lib/pushChain.js +57 -0
  54. package/src/lib/pushChain.js.map +1 -0
  55. package/src/lib/universal/account/account.d.ts +51 -0
  56. package/src/lib/universal/account/account.js +114 -0
  57. package/src/lib/universal/account/account.js.map +1 -0
  58. package/src/lib/universal/account/index.d.ts +1 -0
  59. package/src/lib/universal/account/index.js +5 -0
  60. package/src/lib/universal/account/index.js.map +1 -0
  61. package/src/lib/universal/signer/index.d.ts +1 -0
  62. package/src/lib/universal/signer/index.js +5 -0
  63. package/src/lib/universal/signer/index.js.map +1 -0
  64. package/src/lib/universal/signer/signer.d.ts +40 -0
  65. package/src/lib/universal/signer/signer.js +138 -0
  66. package/src/lib/universal/signer/signer.js.map +1 -0
  67. package/src/lib/universal/universal.types.d.ts +52 -0
  68. package/src/lib/universal/universal.types.js +3 -0
  69. package/src/lib/universal/universal.types.js.map +1 -0
  70. package/src/lib/utils.d.ts +53 -0
  71. package/src/lib/utils.js +58 -0
  72. package/src/lib/utils.js.map +1 -0
  73. package/src/lib/vm-client/evm-client.d.ts +173 -0
  74. package/src/lib/vm-client/evm-client.js +244 -0
  75. package/src/lib/vm-client/evm-client.js.map +1 -0
  76. package/src/lib/vm-client/svm-client.d.ts +42 -0
  77. package/src/lib/vm-client/svm-client.js +136 -0
  78. package/src/lib/vm-client/svm-client.js.map +1 -0
  79. package/src/lib/vm-client/vm-client.types.d.ts +49 -0
  80. package/src/lib/vm-client/vm-client.types.js +3 -0
  81. package/src/lib/vm-client/vm-client.types.js.map +1 -0
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvmClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const viem_1 = require("viem");
6
+ /**
7
+ * EVM client for reading and writing to Ethereum-compatible chains
8
+ *
9
+ * @example
10
+ * // Initialize with an RPC URL
11
+ * const evmClient = new EvmClient({
12
+ * rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/your-api-key'
13
+ * });
14
+ */
15
+ class EvmClient {
16
+ constructor({ rpcUrl }) {
17
+ this.publicClient = (0, viem_1.createPublicClient)({
18
+ transport: (0, viem_1.http)(rpcUrl),
19
+ });
20
+ }
21
+ /**
22
+ * Returns the balance (in wei) of an EVM address.
23
+ *
24
+ * @param address - The EVM address to check balance for
25
+ * @returns Balance as a bigint in wei
26
+ *
27
+ * @example
28
+ * // Get balance of an address
29
+ * const balance = await evmClient.getBalance('0x123...');
30
+ * console.log(`Balance: ${balance} wei`);
31
+ *
32
+ * @example
33
+ * // Check if an address has zero balance
34
+ * const newAddress = privateKeyToAccount(generatePrivateKey()).address;
35
+ * const balance = await evmClient.getBalance(newAddress);
36
+ * if (balance === BigInt(0)) {
37
+ * console.log('Address has no funds');
38
+ * }
39
+ */
40
+ getBalance(address) {
41
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
+ return this.publicClient.getBalance({ address });
43
+ });
44
+ }
45
+ /**
46
+ * Performs a read-only call to a smart contract.
47
+ *
48
+ * @param params - Parameters including ABI, contract address, function name, and args
49
+ * @returns The result of the contract call with the specified type
50
+ *
51
+ * @example
52
+ * // Read a greeting value from a contract
53
+ * const greeting = await evmClient.readContract<string>({
54
+ * abi: parseAbi(['function greet() view returns (string)']),
55
+ * address: '0x2ba5873eF818BEE57645B7d674149041C44F42c6',
56
+ * functionName: 'greet',
57
+ * });
58
+ * console.log(`Current greeting: ${greeting}`);
59
+ *
60
+ * @example
61
+ * // Reading with arguments
62
+ * const balance = await evmClient.readContract<bigint>({
63
+ * abi: parseAbi(['function balanceOf(address) view returns (uint256)']),
64
+ * address: '0xTokenAddress',
65
+ * functionName: 'balanceOf',
66
+ * args: ['0xUserAddress'],
67
+ * });
68
+ */
69
+ readContract(_a) {
70
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ abi, address, functionName, args = [], }) {
71
+ return this.publicClient.readContract({
72
+ abi: abi,
73
+ address: address,
74
+ functionName,
75
+ args,
76
+ });
77
+ });
78
+ }
79
+ /**
80
+ * Writes a transaction to a smart contract using a UniversalSigner.
81
+ * This function handles contract interaction by encoding function data
82
+ * and sending the transaction through sendTransaction.
83
+ *
84
+ * @param params - Parameters including ABI, contract address, function name, args, value and signer
85
+ * @returns Transaction hash as a hex string
86
+ *
87
+ * @example
88
+ * // Set a new greeting on a contract
89
+ * const txHash = await evmClient.writeContract({
90
+ * abi: parseAbi(['function setGreeting(string _greeting)']),
91
+ * address: '0x2ba5873eF818BEE57645B7d674149041C44F42c6',
92
+ * functionName: 'setGreeting',
93
+ * args: ['Hello from Push SDK!'],
94
+ * signer: universalSigner,
95
+ * });
96
+ * console.log(`Transaction sent: ${txHash}`);
97
+ *
98
+ * @example
99
+ * // Sending ether with a contract interaction
100
+ * const txHash = await evmClient.writeContract({
101
+ * abi: parseAbi(['function deposit() payable']),
102
+ * address: '0xContractAddress',
103
+ * functionName: 'deposit',
104
+ * value: parseEther('0.1'), // Send 0.1 ETH
105
+ * signer: universalSigner,
106
+ * });
107
+ */
108
+ writeContract(_a) {
109
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ abi, address, functionName, args = [], value = (0, viem_1.parseEther)('0'), signer, }) {
110
+ const data = (0, viem_1.encodeFunctionData)({
111
+ abi: abi,
112
+ functionName,
113
+ args,
114
+ });
115
+ return this.sendTransaction({
116
+ to: address,
117
+ data,
118
+ value,
119
+ signer,
120
+ });
121
+ });
122
+ }
123
+ /**
124
+ * Sends a raw EVM transaction using a UniversalSigner.
125
+ * This handles the full transaction flow:
126
+ * 1. Gets nonce, estimates gas, and gets current fee data
127
+ * 2. Serializes and signs the transaction
128
+ * 3. Broadcasts the signed transaction to the network
129
+ *
130
+ * @param params - Transaction parameters including destination, data, value and signer
131
+ * @returns Transaction hash as a hex string
132
+ *
133
+ * @example
134
+ * // Send a simple ETH transfer
135
+ * const txHash = await evmClient.sendTransaction({
136
+ * to: '0xRecipientAddress',
137
+ * data: '0x', // empty data for a simple transfer
138
+ * value: parseEther('0.01'),
139
+ * signer: universalSigner,
140
+ * });
141
+ * console.log(`ETH transfer sent: ${txHash}`);
142
+ */
143
+ sendTransaction(_a) {
144
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ to, data, value = (0, viem_1.parseEther)('0'), signer, }) {
145
+ const [nonce, gas, feePerGas] = yield Promise.all([
146
+ this.publicClient.getTransactionCount({
147
+ address: signer.address,
148
+ }),
149
+ this.publicClient.estimateGas({
150
+ account: signer.address,
151
+ to,
152
+ data,
153
+ value,
154
+ }),
155
+ this.publicClient.estimateFeesPerGas(),
156
+ ]);
157
+ const chainId = yield this.publicClient.getChainId();
158
+ const unsignedTx = (0, viem_1.serializeTransaction)({
159
+ chainId,
160
+ type: 'eip1559',
161
+ to,
162
+ data,
163
+ gas,
164
+ nonce,
165
+ maxFeePerGas: feePerGas.maxFeePerGas,
166
+ maxPriorityFeePerGas: feePerGas.maxPriorityFeePerGas,
167
+ value,
168
+ });
169
+ if (!signer.signTransaction) {
170
+ throw new Error('signer.signTransaction is undefined');
171
+ }
172
+ const signedTx = yield signer.signTransaction((0, viem_1.hexToBytes)(unsignedTx));
173
+ return this.publicClient.sendRawTransaction({
174
+ serializedTransaction: (0, viem_1.bytesToHex)(signedTx),
175
+ });
176
+ });
177
+ }
178
+ /**
179
+ * Estimates the gas required for a transaction.
180
+ *
181
+ * @param params - Parameters including from/to addresses, value and optional data
182
+ * @returns Estimated gas as a bigint
183
+ *
184
+ * @example
185
+ * // Estimate gas for a simple transfer
186
+ * const gasEstimate = await evmClient.estimateGas({
187
+ * from: '0xSenderAddress',
188
+ * to: '0xRecipientAddress',
189
+ * value: parseEther('0.01'),
190
+ * });
191
+ * console.log(`Estimated gas: ${gasEstimate}`);
192
+ *
193
+ * @example
194
+ * // Estimate gas for a contract interaction
195
+ * const data = encodeFunctionData({
196
+ * abi: parseAbi(['function setGreeting(string)']),
197
+ * functionName: 'setGreeting',
198
+ * args: ['New greeting'],
199
+ * });
200
+ *
201
+ * const gasEstimate = await evmClient.estimateGas({
202
+ * from: universalSigner.address as `0x${string}`,
203
+ * to: '0xContractAddress',
204
+ * data,
205
+ * value: BigInt(0),
206
+ * });
207
+ */
208
+ estimateGas(_a) {
209
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ from, to, value, data, }) {
210
+ return this.publicClient.estimateGas({
211
+ account: from || undefined,
212
+ to,
213
+ value,
214
+ data,
215
+ });
216
+ });
217
+ }
218
+ /**
219
+ * Gets the current gas price on the network.
220
+ * This is primarily used for legacy transactions, but can be useful
221
+ * for gas cost estimation in EIP-1559 transactions as well.
222
+ *
223
+ * @returns Current gas price in wei as a bigint
224
+ *
225
+ * @example
226
+ * // Get current gas price for cost estimation
227
+ * const gasPrice = await evmClient.getGasPrice();
228
+ * console.log(`Current gas price: ${gasPrice} wei`);
229
+ *
230
+ * @example
231
+ * // Calculate total cost of a transaction
232
+ * const gasPrice = await evmClient.getGasPrice();
233
+ * const gasEstimate = await evmClient.estimateGas({...});
234
+ * const totalCost = gasPrice * gasEstimate;
235
+ * console.log(`Estimated transaction cost: ${totalCost} wei`);
236
+ */
237
+ getGasPrice() {
238
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
239
+ return this.publicClient.getGasPrice();
240
+ });
241
+ }
242
+ }
243
+ exports.EvmClient = EvmClient;
244
+ //# sourceMappingURL=evm-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm-client.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/vm-client/evm-client.ts"],"names":[],"mappings":";;;;AAMA,+BAWc;AAEd;;;;;;;;GAQG;AACH,MAAa,SAAS;IAGpB,YAAY,EAAE,MAAM,EAAiB;QACnC,IAAI,CAAC,YAAY,GAAG,IAAA,yBAAkB,EAAC;YACrC,SAAS,EAAE,IAAA,WAAI,EAAC,MAAM,CAAC;SACxB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACG,UAAU,CAAC,OAAsB;;YACrC,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,YAAY;qEAAc,EAC9B,GAAG,EACH,OAAO,EACP,YAAY,EACZ,IAAI,GAAG,EAAE,GACU;YACnB,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;gBACpC,GAAG,EAAE,GAAU;gBACf,OAAO,EAAE,OAAwB;gBACjC,YAAY;gBACZ,IAAI;aACL,CAAe,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,aAAa;qEAAC,EAClB,GAAG,EACH,OAAO,EACP,YAAY,EACZ,IAAI,GAAG,EAAE,EACT,KAAK,GAAG,IAAA,iBAAU,EAAC,GAAG,CAAC,EACvB,MAAM,GACc;YACpB,MAAM,IAAI,GAAG,IAAA,yBAAkB,EAAC;gBAC9B,GAAG,EAAE,GAAU;gBACf,YAAY;gBACZ,IAAI;aACL,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC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E,IAAA,iBAAU,EAAC,QAAQ,CAAC;aAC5C,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,WAAW;qEAAC,EAChB,IAAI,EACJ,EAAE,EACF,KAAK,EACL,IAAI,GAML;YACC,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC;gBACnC,OAAO,EAAE,IAAI,IAAI,SAAS;gBAC1B,EAAE;gBACF,KAAK;gBACL,IAAI;aACL,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACG,WAAW;;YACf,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;QACzC,CAAC;KAAA;CACF;AArQD,8BAqQC"}
@@ -0,0 +1,42 @@
1
+ import { Keypair, TransactionInstruction } from '@solana/web3.js';
2
+ import { ClientOptions, ReadContractParams, WriteContractParams } from './vm-client.types';
3
+ import { UniversalSigner } from '../universal/universal.types';
4
+ /**
5
+ * Solana-compatible VM client for reading and writing SVM-based chains.
6
+ */
7
+ export declare class SvmClient {
8
+ private readonly connection;
9
+ constructor({ rpcUrl }: ClientOptions);
10
+ /**
11
+ * Returns the balance (in lamports) of a Solana address.
12
+ */
13
+ getBalance(address: string): Promise<bigint>;
14
+ /**
15
+ * Reads a full program account using Anchor IDL.
16
+ * `functionName` must match the account layout name in the IDL.
17
+ */
18
+ readContract<T = unknown>({ abi, functionName, args, }: ReadContractParams): Promise<T>;
19
+ /**
20
+ * Sends a Solana transaction using a smart contract instruction.
21
+ */
22
+ writeContract({ abi, signer, functionName, args, accounts, extraSigners, }: WriteContractParams): Promise<string>;
23
+ /**
24
+ * Sends a set of instructions as a manually-signed Solana transaction.
25
+ */
26
+ sendTransaction({ instruction, signer, extraSigners, }: {
27
+ instruction: TransactionInstruction;
28
+ signer: UniversalSigner;
29
+ extraSigners?: Keypair[];
30
+ }): Promise<string>;
31
+ /**
32
+ * Waits for a transaction to be confirmed on the blockchain.
33
+ */
34
+ confirmTransaction(signature: string, timeout?: number): Promise<void>;
35
+ /**
36
+ * Estimates the fee (in lamports) to send a transaction with the given instructions.
37
+ */
38
+ estimateGas({ instructions, signer, }: {
39
+ instructions: TransactionInstruction[];
40
+ signer: UniversalSigner;
41
+ }): Promise<bigint>;
42
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SvmClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const anchor_1 = require("@coral-xyz/anchor");
7
+ /**
8
+ * Solana-compatible VM client for reading and writing SVM-based chains.
9
+ */
10
+ class SvmClient {
11
+ constructor({ rpcUrl }) {
12
+ this.connection = new web3_js_1.Connection(rpcUrl, 'confirmed');
13
+ }
14
+ /**
15
+ * Returns the balance (in lamports) of a Solana address.
16
+ */
17
+ getBalance(address) {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ const pubkey = new web3_js_1.PublicKey(address);
20
+ const lamports = yield this.connection.getBalance(pubkey);
21
+ return BigInt(lamports);
22
+ });
23
+ }
24
+ /**
25
+ * Reads a full program account using Anchor IDL.
26
+ * `functionName` must match the account layout name in the IDL.
27
+ */
28
+ readContract(_a) {
29
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ abi, functionName, args = [], }) {
30
+ const provider = new anchor_1.AnchorProvider(this.connection, new anchor_1.Wallet(new web3_js_1.Keypair()), { preflightCommitment: 'confirmed' });
31
+ // Anchor v0.31 constructor no longer takes programId
32
+ // Use the IDL's embedded metadata.address instead
33
+ const program = new anchor_1.Program(abi, provider);
34
+ const pubkey = new web3_js_1.PublicKey(args[0]);
35
+ // Cast account namespace to any to allow dynamic string
36
+ const accountNamespace = program.account;
37
+ const account = yield accountNamespace[functionName].fetch(pubkey);
38
+ return account;
39
+ });
40
+ }
41
+ /**
42
+ * Sends a Solana transaction using a smart contract instruction.
43
+ */
44
+ writeContract(_a) {
45
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ abi, signer, functionName, args = [], accounts = {}, extraSigners = [], }) {
46
+ const provider = new anchor_1.AnchorProvider(this.connection, new anchor_1.Wallet(new web3_js_1.Keypair()), { preflightCommitment: 'confirmed' });
47
+ // NEW: Drop explicit programId. Anchor v0.31 infers it from IDL.metadata.address
48
+ const program = new anchor_1.Program(abi, provider);
49
+ // Convert BigInt arguments to BN instances for Anchor compatibility. Anchor program expects BN for BigInts
50
+ const convertedArgs = args.map((arg) => {
51
+ if (typeof arg === 'bigint') {
52
+ return new anchor_1.BN(arg.toString());
53
+ }
54
+ return arg;
55
+ });
56
+ // Build the method context
57
+ const methodContext = convertedArgs.length > 0
58
+ ? program.methods[functionName](...convertedArgs)
59
+ : program.methods[functionName]();
60
+ let instructionBuilder = methodContext;
61
+ if (Object.keys(accounts).length > 0) {
62
+ instructionBuilder = instructionBuilder.accounts(accounts);
63
+ }
64
+ const instruction = yield instructionBuilder.instruction();
65
+ return this.sendTransaction({
66
+ instruction,
67
+ signer,
68
+ extraSigners,
69
+ });
70
+ });
71
+ }
72
+ /**
73
+ * Sends a set of instructions as a manually-signed Solana transaction.
74
+ */
75
+ sendTransaction(_a) {
76
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ instruction, signer, extraSigners = [], }) {
77
+ const feePayerPubkey = new web3_js_1.PublicKey(signer.address);
78
+ const { blockhash, lastValidBlockHeight } = yield this.connection.getLatestBlockhash('finalized');
79
+ const tx = new web3_js_1.Transaction({
80
+ feePayer: feePayerPubkey,
81
+ blockhash,
82
+ lastValidBlockHeight,
83
+ }).add(instruction);
84
+ // Sign with all provided keypairs
85
+ if (extraSigners.length > 0) {
86
+ tx.partialSign(...extraSigners);
87
+ }
88
+ const messageBytes = tx.serializeMessage();
89
+ const signature = yield signer.signTransaction(messageBytes);
90
+ tx.addSignature(feePayerPubkey, Buffer.from(signature));
91
+ const rawTx = tx.serialize();
92
+ return yield this.connection.sendRawTransaction(rawTx);
93
+ });
94
+ }
95
+ /**
96
+ * Waits for a transaction to be confirmed on the blockchain.
97
+ */
98
+ confirmTransaction(signature_1) {
99
+ return tslib_1.__awaiter(this, arguments, void 0, function* (signature, timeout = 30000) {
100
+ const startTime = Date.now();
101
+ while (Date.now() - startTime < timeout) {
102
+ const status = yield this.connection.getSignatureStatus(signature);
103
+ if (status === null || status === void 0 ? void 0 : status.value) {
104
+ if (status.value.err) {
105
+ throw new Error(`Transaction failed: ${JSON.stringify(status.value.err)}`);
106
+ }
107
+ if (status.value.confirmationStatus === 'confirmed' ||
108
+ status.value.confirmationStatus === 'finalized') {
109
+ return;
110
+ }
111
+ }
112
+ yield new Promise((r) => setTimeout(r, 500));
113
+ }
114
+ throw new Error(`Transaction confirmation timeout after ${timeout}ms`);
115
+ });
116
+ }
117
+ /**
118
+ * Estimates the fee (in lamports) to send a transaction with the given instructions.
119
+ */
120
+ estimateGas(_a) {
121
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ instructions, signer, }) {
122
+ const feePayer = new web3_js_1.PublicKey(signer.address);
123
+ const { blockhash, lastValidBlockHeight } = yield this.connection.getLatestBlockhash();
124
+ const tx = new web3_js_1.Transaction({ blockhash, lastValidBlockHeight, feePayer });
125
+ if (instructions.length)
126
+ tx.add(...instructions);
127
+ const message = tx.compileMessage();
128
+ const feeResp = yield this.connection.getFeeForMessage(message);
129
+ if (!(feeResp === null || feeResp === void 0 ? void 0 : feeResp.value))
130
+ throw new Error('Failed to estimate fee');
131
+ return BigInt(feeResp.value);
132
+ });
133
+ }
134
+ }
135
+ exports.SvmClient = SvmClient;
136
+ //# sourceMappingURL=svm-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svm-client.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/vm-client/svm-client.ts"],"names":[],"mappings":";;;;AAAA,6CAMyB;AAMzB,8CAAwE;AAGxE;;GAEG;AACH,MAAa,SAAS;IAGpB,YAAY,EAAE,MAAM,EAAiB;QACnC,IAA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**
5
+ * Common options used by all VM clients (EVM, SVM, etc.)
6
+ */
7
+ export interface ClientOptions {
8
+ rpcUrl: string;
9
+ }
10
+ /**
11
+ * Parameters for reading from a smart contract (read-only call).
12
+ */
13
+ export interface ReadContractParams {
14
+ /**
15
+ * EVM contract address
16
+ * SVM program id
17
+ */
18
+ address: string;
19
+ /**
20
+ * EVM abi
21
+ * SVM idl
22
+ */
23
+ abi: Abi | any;
24
+ /**
25
+ * EVM contract fn name
26
+ * SVM PDA var name
27
+ */
28
+ functionName: string;
29
+ /**
30
+ * EVM fn vars
31
+ * SVM - undefined
32
+ */
33
+ args?: any[];
34
+ }
35
+ /**
36
+ * Parameters for writing to a smart contract (requires signature).
37
+ */
38
+ export interface WriteContractParams extends ReadContractParams {
39
+ value?: bigint;
40
+ signer: UniversalSigner;
41
+ /**
42
+ * **For Solana only** Dynamic accounts to pass to the solana program instruction
43
+ */
44
+ accounts?: Record<string, PublicKey>;
45
+ /**
46
+ * **For Solana only** Keypairs that should sign the transaction
47
+ */
48
+ extraSigners?: Keypair[];
49
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=vm-client.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vm-client.types.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/vm-client/vm-client.types.ts"],"names":[],"mappings":""}