sdk-triggerx 0.1.31 → 0.1.33

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.
@@ -0,0 +1,20 @@
1
+ import { ethers } from 'ethers';
2
+ export declare const depositEth: (ethAmount: bigint, signer: ethers.Signer) => Promise<{
3
+ success: boolean;
4
+ data?: any;
5
+ error?: string;
6
+ errorCode?: string;
7
+ errorType?: string;
8
+ details?: any;
9
+ }>;
10
+ /**
11
+ * @deprecated Use depositEth instead. This is an alias for backward compatibility.
12
+ */
13
+ export declare const topupTg: (ethAmount: bigint, signer: ethers.Signer) => Promise<{
14
+ success: boolean;
15
+ data?: any;
16
+ error?: string;
17
+ errorCode?: string;
18
+ errorType?: string;
19
+ details?: any;
20
+ }>;
@@ -0,0 +1,102 @@
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.topupTg = exports.depositEth = void 0;
7
+ const GasRegistry_json_1 = __importDefault(require("../contracts/abi/GasRegistry.json"));
8
+ const contractUtils_1 = require("../contracts/contractUtils");
9
+ const errors_1 = require("../utils/errors");
10
+ const depositEth = async (ethAmount, signer) => {
11
+ console.log('depositing ETH balance', ethAmount);
12
+ // Validate inputs
13
+ if (!ethAmount || ethAmount <= 0n) {
14
+ return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('ethAmount', 'ETH amount must be a positive bigint'), 'Validation error');
15
+ }
16
+ if (!signer) {
17
+ return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('signer', 'Signer is required'), 'Validation error');
18
+ }
19
+ try {
20
+ // Get contract address and create contract instances with SDK RPC provider
21
+ // This ensures we can interact with the contract even if user's RPC fails
22
+ let gasRegistryContractAddress;
23
+ let contract;
24
+ let contractWithSigner;
25
+ let rpcProvider;
26
+ let resolvedChainId;
27
+ let signerAddress;
28
+ try {
29
+ // Get signer address (this doesn't require the signer's provider to work)
30
+ signerAddress = await signer.getAddress();
31
+ // Resolve chain ID from signer
32
+ resolvedChainId = await (0, contractUtils_1.resolveChainId)(signer);
33
+ // Get contract address
34
+ gasRegistryContractAddress = (0, contractUtils_1.getContractAddress)(resolvedChainId, 'gasRegistry');
35
+ // Create contract instances with SDK RPC provider
36
+ const contractInstances = await (0, contractUtils_1.createContractWithSdkRpcAndSigner)(gasRegistryContractAddress, GasRegistry_json_1.default, signer, resolvedChainId);
37
+ contract = contractInstances.contract;
38
+ contractWithSigner = contractInstances.contractWithSigner;
39
+ rpcProvider = contractInstances.rpcProvider;
40
+ }
41
+ catch (configError) {
42
+ if (configError instanceof errors_1.ConfigurationError) {
43
+ return (0, errors_1.createErrorResponse)(configError, 'Configuration error');
44
+ }
45
+ return (0, errors_1.createErrorResponse)(new errors_1.ConfigurationError('Failed to initialize contract', { originalError: configError }), 'Configuration error');
46
+ }
47
+ // Convert ethAmount to wei if needed
48
+ console.log('ethAmount', ethAmount);
49
+ const amountInEthWei = typeof ethAmount === 'bigint' ? ethAmount : BigInt(ethAmount);
50
+ console.log('amountInEthWei', amountInEthWei);
51
+ // Estimate gas for the transaction using SDK RPC provider
52
+ // This ensures gas estimation works even if user's RPC fails
53
+ let estimatedGas;
54
+ try {
55
+ console.log('Estimating gas using SDK RPC provider...');
56
+ // Use contract instance with SDK RPC provider for estimation
57
+ // Specify the signer's address in the estimation options
58
+ estimatedGas = await contract.depositETH.estimateGas(amountInEthWei, {
59
+ value: amountInEthWei,
60
+ from: signerAddress // Specify the sender address for accurate estimation
61
+ });
62
+ console.log('Estimated gas (using SDK RPC):', estimatedGas.toString());
63
+ // Add 10% buffer to ensure transaction doesn't fail
64
+ const gasWithBuffer = (estimatedGas * BigInt(110)) / BigInt(100);
65
+ console.log('Gas with 10% buffer:', gasWithBuffer.toString());
66
+ // Execute transaction using signer (for signing)
67
+ const tx = await contractWithSigner.depositETH(amountInEthWei, {
68
+ value: amountInEthWei,
69
+ gasLimit: gasWithBuffer
70
+ });
71
+ await (0, contractUtils_1.waitForTransactionReceiptWithRpcFallback)(tx, rpcProvider);
72
+ return { success: true, data: tx };
73
+ }
74
+ catch (gasEstimateError) {
75
+ // If gas estimation fails, try without gas limit (let provider estimate)
76
+ console.warn('Gas estimation failed (using SDK RPC), proceeding without gas limit:', gasEstimateError);
77
+ const tx = await contractWithSigner.depositETH(amountInEthWei, { value: amountInEthWei });
78
+ await (0, contractUtils_1.waitForTransactionReceiptWithRpcFallback)(tx, rpcProvider);
79
+ return { success: true, data: tx };
80
+ }
81
+ }
82
+ catch (error) {
83
+ console.error('Error depositing ETH:', error);
84
+ if (error instanceof Error) {
85
+ if (error.message.includes('network') || error.message.includes('timeout')) {
86
+ return (0, errors_1.createErrorResponse)(new errors_1.NetworkError('Network error during ETH deposit', { originalError: error, ethAmount }), 'Network error');
87
+ }
88
+ else if (error.message.includes('contract') || error.message.includes('transaction')) {
89
+ return (0, errors_1.createErrorResponse)(new errors_1.ContractError('Contract error during ETH deposit', { originalError: error, ethAmount }), 'Contract error');
90
+ }
91
+ else if (error.message.includes('insufficient funds') || error.message.includes('balance')) {
92
+ return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('balance', 'Insufficient funds for ETH deposit', { originalError: error, ethAmount }), 'Validation error');
93
+ }
94
+ }
95
+ return (0, errors_1.createErrorResponse)(error, 'Failed to deposit ETH');
96
+ }
97
+ };
98
+ exports.depositEth = depositEth;
99
+ /**
100
+ * @deprecated Use depositEth instead. This is an alias for backward compatibility.
101
+ */
102
+ exports.topupTg = exports.depositEth;
@@ -0,0 +1,26 @@
1
+ import { ethers } from 'ethers';
2
+ /**
3
+ * Withdraw ETH from the Gas Registry.
4
+ * @param signer ethers.Signer instance
5
+ * @param amountETH The amount of ETH to withdraw (as a string or BigNumberish)
6
+ * @returns The transaction object or error response
7
+ */
8
+ export declare const withdrawEth: (signer: ethers.Signer, amountETHwei: string | ethers.BigNumberish) => Promise<{
9
+ success: boolean;
10
+ data?: any;
11
+ error?: string;
12
+ errorCode?: string;
13
+ errorType?: string;
14
+ details?: any;
15
+ }>;
16
+ /**
17
+ * @deprecated Use withdrawEth instead. This is an alias for backward compatibility.
18
+ */
19
+ export declare const withdrawTg: (signer: ethers.Signer, amountETHwei: string | ethers.BigNumberish) => Promise<{
20
+ success: boolean;
21
+ data?: any;
22
+ error?: string;
23
+ errorCode?: string;
24
+ errorType?: string;
25
+ details?: any;
26
+ }>;
@@ -0,0 +1,89 @@
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.withdrawTg = exports.withdrawEth = void 0;
7
+ const GasRegistry_json_1 = __importDefault(require("../contracts/abi/GasRegistry.json"));
8
+ const contractUtils_1 = require("../contracts/contractUtils");
9
+ const errors_1 = require("../utils/errors");
10
+ /**
11
+ * Withdraw ETH from the Gas Registry.
12
+ * @param signer ethers.Signer instance
13
+ * @param amountETH The amount of ETH to withdraw (as a string or BigNumberish)
14
+ * @returns The transaction object or error response
15
+ */
16
+ const withdrawEth = async (signer, amountETHwei) => {
17
+ // Validate inputs
18
+ if (!signer) {
19
+ return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('signer', 'Signer is required'), 'Validation error');
20
+ }
21
+ if (!amountETHwei || (typeof amountETHwei === 'string' && amountETHwei.trim() === '') || Number(amountETHwei) <= 0) {
22
+ return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('amountETHwei', 'Amount must be a positive number'), 'Validation error');
23
+ }
24
+ try {
25
+ // Resolve chain ID and create contract instances with SDK RPC provider
26
+ let resolvedChainId;
27
+ let contract;
28
+ let contractWithSigner;
29
+ let rpcProvider;
30
+ let signerAddress;
31
+ try {
32
+ // Resolve chain ID from signer
33
+ signerAddress = await signer.getAddress();
34
+ resolvedChainId = await (0, contractUtils_1.resolveChainId)(signer);
35
+ // Get contract address
36
+ const gasRegistryContractAddress = (0, contractUtils_1.getContractAddress)(resolvedChainId, 'gasRegistry');
37
+ // Create contract instances with SDK RPC provider
38
+ const contractInstances = await (0, contractUtils_1.createContractWithSdkRpcAndSigner)(gasRegistryContractAddress, GasRegistry_json_1.default, signer, resolvedChainId);
39
+ contract = contractInstances.contract;
40
+ contractWithSigner = contractInstances.contractWithSigner;
41
+ rpcProvider = contractInstances.rpcProvider;
42
+ }
43
+ catch (configError) {
44
+ if (configError instanceof errors_1.ConfigurationError) {
45
+ return (0, errors_1.createErrorResponse)(configError, 'Configuration error');
46
+ }
47
+ return (0, errors_1.createErrorResponse)(new errors_1.ConfigurationError('Failed to initialize contract', { originalError: configError }), 'Configuration error');
48
+ }
49
+ let tx;
50
+ try {
51
+ console.log('Estimating gas for withdrawETHBalance using SDK RPC provider...');
52
+ const estimatedGas = await contract.withdrawETHBalance.estimateGas(amountETHwei, {
53
+ from: signerAddress,
54
+ });
55
+ console.log('Estimated gas (withdrawETHBalance):', estimatedGas.toString());
56
+ const gasWithBuffer = (estimatedGas * BigInt(110)) / BigInt(100);
57
+ console.log('Gas with 10% buffer (withdrawETHBalance):', gasWithBuffer.toString());
58
+ tx = await contractWithSigner.withdrawETHBalance(amountETHwei, {
59
+ gasLimit: gasWithBuffer,
60
+ });
61
+ }
62
+ catch (gasEstimateError) {
63
+ console.warn('Gas estimation failed for withdrawETHBalance (using SDK RPC), proceeding without explicit gas limit:', gasEstimateError);
64
+ tx = await contractWithSigner.withdrawETHBalance(amountETHwei);
65
+ }
66
+ await (0, contractUtils_1.waitForTransactionReceiptWithRpcFallback)(tx, rpcProvider);
67
+ return { success: true, data: tx };
68
+ }
69
+ catch (error) {
70
+ console.error('Error withdrawing ETH:', error);
71
+ if (error instanceof Error) {
72
+ if (error.message.includes('network') || error.message.includes('timeout')) {
73
+ return (0, errors_1.createErrorResponse)(new errors_1.NetworkError('Network error during ETH withdrawal', { originalError: error, amountETHwei }), 'Network error');
74
+ }
75
+ else if (error.message.includes('contract') || error.message.includes('transaction')) {
76
+ return (0, errors_1.createErrorResponse)(new errors_1.ContractError('Contract error during ETH withdrawal', { originalError: error, amountETHwei }), 'Contract error');
77
+ }
78
+ else if (error.message.includes('insufficient') || error.message.includes('balance')) {
79
+ return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('balance', 'Insufficient ETH balance for withdrawal', { originalError: error, amountETHwei }), 'Validation error');
80
+ }
81
+ }
82
+ return (0, errors_1.createErrorResponse)(error, 'Failed to withdraw ETH');
83
+ }
84
+ };
85
+ exports.withdrawEth = withdrawEth;
86
+ /**
87
+ * @deprecated Use withdrawEth instead. This is an alias for backward compatibility.
88
+ */
89
+ exports.withdrawTg = exports.withdrawEth;
package/dist/config.js CHANGED
@@ -13,7 +13,7 @@ exports.CONTRACT_ADDRESSES_BY_CHAIN = {
13
13
  // TESTNET CONFIGURATIONS
14
14
  // OP Sepolia (11155420) - Optimism Sepolia Testnet
15
15
  '11155420': {
16
- gasRegistry: '0x664CB20BCEEc9416D290AC820e5446e61a5c75e4',
16
+ gasRegistry: '0x248E9f1B99F1AC8068254233D1F271ed0e0903D6',
17
17
  jobRegistry: '0x476ACc7949a95e31144cC84b8F6BC7abF0967E4b',
18
18
  safeFactory: '0x04359eDC46Cd6C6BD7F6359512984222BE10F8Be',
19
19
  safeModule: '0xa0bC1477cfc452C05786262c377DE51FB8bc4669',
@@ -22,7 +22,7 @@ exports.CONTRACT_ADDRESSES_BY_CHAIN = {
22
22
  },
23
23
  // Ethereum Sepolia (11155111) - Ethereum Sepolia Testnet
24
24
  '11155111': {
25
- gasRegistry: '0x664CB20BCEEc9416D290AC820e5446e61a5c75e4',
25
+ gasRegistry: '0x248E9f1B99F1AC8068254233D1F271ed0e0903D6',
26
26
  jobRegistry: '0x476ACc7949a95e31144cC84b8F6BC7abF0967E4b',
27
27
  safeFactory: '0xdf76E2A796a206D877086c717979054544B1D9Bc',
28
28
  safeModule: '0xa0bC1477cfc452C05786262c377DE51FB8bc4669',
@@ -31,7 +31,7 @@ exports.CONTRACT_ADDRESSES_BY_CHAIN = {
31
31
  },
32
32
  // Arbitrum Sepolia (421614) - Arbitrum Sepolia Testnet
33
33
  '421614': {
34
- gasRegistry: '0x664CB20BCEEc9416D290AC820e5446e61a5c75e4',
34
+ gasRegistry: '0x248E9f1B99F1AC8068254233D1F271ed0e0903D6',
35
35
  jobRegistry: '0x476ACc7949a95e31144cC84b8F6BC7abF0967E4b',
36
36
  safeFactory: '0x04359eDC46Cd6C6BD7F6359512984222BE10F8Be',
37
37
  safeModule: '0xa0bC1477cfc452C05786262c377DE51FB8bc4669',
@@ -41,7 +41,7 @@ exports.CONTRACT_ADDRESSES_BY_CHAIN = {
41
41
  },
42
42
  // Base Sepolia (84532) - Base Sepolia Testnet
43
43
  '84532': {
44
- gasRegistry: '0x664CB20BCEEc9416D290AC820e5446e61a5c75e4',
44
+ gasRegistry: '0x248E9f1B99F1AC8068254233D1F271ed0e0903D6',
45
45
  jobRegistry: '0x476ACc7949a95e31144cC84b8F6BC7abF0967E4b',
46
46
  safeFactory: '0x04359eDC46Cd6C6BD7F6359512984222BE10F8Be',
47
47
  safeModule: '0xa0bC1477cfc452C05786262c377DE51FB8bc4669',
@@ -51,7 +51,7 @@ exports.CONTRACT_ADDRESSES_BY_CHAIN = {
51
51
  // MAINNET CONFIGURATIONS
52
52
  // Arbitrum One (42161) - Mainnet
53
53
  '42161': {
54
- gasRegistry: '0x93dDB2307F3Af5df85F361E5Cddd898Acd3d132d',
54
+ gasRegistry: '0xe2AC670F7D66c69D547A44D08F9bA1Fc0Fc0f991',
55
55
  jobRegistry: '0xAf1189aFd1F1880F09AeC3Cbc32cf415c735C710',
56
56
  multisendCallOnly: '0x9641d764fc13c8B624c04430C7356C1C7C8102e2',
57
57
  rpcUrl: 'https://arb1.arbitrum.io/rpc',