sdk-triggerx 0.1.20 → 0.1.22

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/client.js CHANGED
@@ -12,7 +12,7 @@ class TriggerXClient {
12
12
  this.client = axios_1.default.create({
13
13
  baseURL: 'https://data.triggerx.network', //'http://localhost:9002', //'https://data.triggerx.network',
14
14
  headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
15
- timeout: 30000, // 30 second timeout
15
+ timeout: 120000, // 120 second timeout
16
16
  ...config,
17
17
  });
18
18
  }
@@ -26,8 +26,15 @@ async function createSafeWalletForUser(factoryAddress, signer, user) {
26
26
  }
27
27
  })
28
28
  .find((e) => e && e.name === 'SafeWalletCreated');
29
+ let safeAddress;
29
30
  if (evt && evt.args && evt.args.safeWallet) {
30
- return evt.args.safeWallet;
31
+ safeAddress = evt.args.safeWallet;
31
32
  }
32
- return await factory.latestSafeWallet(user);
33
+ else {
34
+ safeAddress = await factory.latestSafeWallet(user);
35
+ }
36
+ // Wait a bit for the Safe contract to be fully initialized
37
+ // This is important because Safe proxy contracts need time to be set up
38
+ await new Promise(resolve => setTimeout(resolve, 2000));
39
+ return safeAddress;
33
40
  }
@@ -54,23 +54,37 @@ async function enableSafeModule(safeAddress, signer, moduleAddress) {
54
54
  if (!provider)
55
55
  throw new Error('Signer provider is required');
56
56
  const safeProxy = new ethers_1.ethers.Contract(safeAddress, exports.SAFE_ABI, provider);
57
- // If already enabled, exit early
58
- const already = await safeProxy.isModuleEnabled(moduleAddress);
59
- if (already) {
60
- console.log('Module is already enabled');
61
- return;
57
+ // Check if contract is deployed and initialized
58
+ try {
59
+ // If already enabled, exit early
60
+ const already = await safeProxy.isModuleEnabled(moduleAddress);
61
+ if (already) {
62
+ console.log('Module is already enabled');
63
+ return;
64
+ }
65
+ }
66
+ catch (error) {
67
+ // If we can't decode the result, the Safe might not be fully initialized
68
+ if (error.code === 'BAD_DATA' && error.value === '0x') {
69
+ console.log('Safe wallet not fully initialized yet, waiting a moment...');
70
+ await new Promise(resolve => setTimeout(resolve, 2000));
71
+ }
72
+ else {
73
+ throw error;
74
+ }
62
75
  }
63
- // First, let's try the direct approach for single-owner Safes
76
+ // Verify Safe is properly initialized by checking owners and threshold
64
77
  try {
65
- console.log('Attempting direct enableModule call...');
66
- const safeWithSigner = new ethers_1.ethers.Contract(safeAddress, exports.SAFE_ABI, signer);
67
- const tx = await safeWithSigner.enableModule(moduleAddress);
68
- await tx.wait();
69
- console.log('Module enabled via direct call');
70
- return;
78
+ const [owners, threshold] = await Promise.all([
79
+ safeProxy.getOwners(),
80
+ safeProxy.getThreshold(),
81
+ ]);
82
+ const signerAddress = await signer.getAddress();
83
+ console.log(`Safe has ${owners.length} owner(s), threshold: ${threshold}`);
84
+ console.log(`Signer: ${signerAddress}, Owners: ${owners.join(', ')}`);
71
85
  }
72
86
  catch (error) {
73
- console.log('Direct call failed, trying execTransaction approach...');
87
+ console.log('Could not verify Safe owners, proceeding anyway...');
74
88
  }
75
89
  // If direct call fails, use execTransaction with proper signature
76
90
  const safeNonce = await safeProxy.nonce();
@@ -99,11 +113,17 @@ async function enableSafeModule(safeAddress, signer, moduleAddress) {
99
113
  // Execute the transaction through Safe's execTransaction
100
114
  const safeProxyWithSigner = new ethers_1.ethers.Contract(safeAddress, exports.SAFE_ABI, signer);
101
115
  const tx = await safeProxyWithSigner.execTransaction(to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, signature);
102
- await tx.wait();
116
+ console.log('Waiting for transaction confirmation...');
117
+ const receipt = await tx.wait();
118
+ console.log(`Transaction confirmed in block ${receipt.blockNumber}`);
119
+ // Wait a bit for state to propagate
120
+ await new Promise(resolve => setTimeout(resolve, 2000));
103
121
  // Verify module is enabled
104
122
  const isNowEnabled = await safeProxy.isModuleEnabled(moduleAddress);
105
123
  if (!isNowEnabled) {
124
+ console.error('Module is still not enabled after transaction');
125
+ console.error(`Transaction hash: ${receipt.hash}`);
106
126
  throw new Error("Module verification failed");
107
127
  }
108
- console.log('Module enabled successfully via execTransaction');
128
+ console.log('Module enabled successfully via execTransaction');
109
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdk-triggerx",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "SDK for interacting with the TriggerX backend and smart contracts.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",