sdk-triggerx 0.1.12 → 0.1.15

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.
@@ -6,10 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.checkTgBalance = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const GasRegistry_json_1 = __importDefault(require("../contracts/abi/GasRegistry.json"));
9
+ const config_1 = require("../config");
9
10
  const checkTgBalance = async (signer) => {
10
- const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS || '0x204F9278D6BB7714D7A40842423dFd5A27cC1b88';
11
+ const network = await signer.provider?.getNetwork();
12
+ const chainId = network?.chainId ? network.chainId.toString() : undefined;
13
+ const { gasRegistry } = (0, config_1.getChainAddresses)(chainId);
14
+ const gasRegistryContractAddress = gasRegistry;
11
15
  if (!gasRegistryContractAddress) {
12
- throw new Error('GAS_REGISTRY_CONTRACT_ADDRESS is not set in the environment variables');
16
+ throw new Error('GasRegistry address not configured for this chain. Update config mapping.');
13
17
  }
14
18
  const contract = new ethers_1.ethers.Contract(gasRegistryContractAddress, GasRegistry_json_1.default, signer);
15
19
  const address = await signer.getAddress();
package/dist/api/jobs.js CHANGED
@@ -12,9 +12,9 @@ const ethers_1 = require("ethers");
12
12
  const JobRegistry_json_1 = __importDefault(require("../contracts/abi/JobRegistry.json"));
13
13
  const topupTg_1 = require("./topupTg");
14
14
  const checkTgBalance_1 = require("./checkTgBalance");
15
+ const config_1 = require("../config");
15
16
  const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
16
17
  const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
17
- const JOB_REGISTRY_ADDRESS = '0x476ACc7949a95e31144cC84b8F6BC7abF0967E4b'; // Set your fixed contract address here
18
18
  function toCreateJobDataFromTime(input, balances, userAddress, jobCostPrediction) {
19
19
  return {
20
20
  job_id: JOB_ID,
@@ -123,6 +123,14 @@ async function createJob(client, params) {
123
123
  // Use the API key from the client instance
124
124
  const apiKey = client.getApiKey();
125
125
  const userAddress = await signer.getAddress();
126
+ // Resolve chain-specific addresses
127
+ const network = await signer.provider?.getNetwork();
128
+ const chainIdStr = network?.chainId ? network.chainId.toString() : undefined;
129
+ const { jobRegistry } = (0, config_1.getChainAddresses)(chainIdStr);
130
+ const JOB_REGISTRY_ADDRESS = jobRegistry;
131
+ if (!JOB_REGISTRY_ADDRESS) {
132
+ return { success: false, error: 'JobRegistry address not configured for this chain. Update config mapping.' };
133
+ }
126
134
  let jobTitle, timeFrame, targetContractAddress, jobType;
127
135
  if ('jobTitle' in jobInput)
128
136
  jobTitle = jobInput.jobTitle;
@@ -160,7 +168,8 @@ async function createJob(client, params) {
160
168
  encodedData = encodeJobType1Data(jobInput.timeInterval ?? 0);
161
169
  }
162
170
  else if (jobType === 2) {
163
- encodedData = encodeJobType2Data(jobInput.timeInterval ?? 0, jobInput.dynamicArgumentsScriptUrl || '');
171
+ const ipfsBytes32 = jobInput.dynamicArgumentsScriptUrl ? ethers_1.ethers.id(jobInput.dynamicArgumentsScriptUrl) : ethers_1.ethers.ZeroHash;
172
+ encodedData = encodeJobType2Data(jobInput.timeInterval ?? 0, ipfsBytes32);
164
173
  }
165
174
  }
166
175
  // Event-based jobs
@@ -169,7 +178,8 @@ async function createJob(client, params) {
169
178
  encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
170
179
  }
171
180
  else if (jobType === 4 || jobType === 6) {
172
- encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
181
+ const ipfsBytes32 = jobInput.dynamicArgumentsScriptUrl ? ethers_1.ethers.id(jobInput.dynamicArgumentsScriptUrl) : ethers_1.ethers.ZeroHash;
182
+ encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, ipfsBytes32);
173
183
  }
174
184
  }
175
185
  // Condition-based jobs
@@ -178,7 +188,8 @@ async function createJob(client, params) {
178
188
  encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
179
189
  }
180
190
  else if (jobType === 4 || jobType === 6) {
181
- encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
191
+ const ipfsBytes32 = jobInput.dynamicArgumentsScriptUrl ? ethers_1.ethers.id(jobInput.dynamicArgumentsScriptUrl) : ethers_1.ethers.ZeroHash;
192
+ encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, ipfsBytes32);
182
193
  }
183
194
  }
184
195
  }
@@ -6,12 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.topupTg = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const GasRegistry_json_1 = __importDefault(require("../contracts/abi/GasRegistry.json"));
9
+ const config_1 = require("../config");
9
10
  const topupTg = async (tgAmount, signer) => {
10
- const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS || '0x204F9278D6BB7714D7A40842423dFd5A27cC1b88';
11
+ const network = await signer.provider?.getNetwork();
12
+ const chainId = network?.chainId ? network.chainId.toString() : undefined;
13
+ const { gasRegistry } = (0, config_1.getChainAddresses)(chainId);
14
+ const gasRegistryContractAddress = gasRegistry;
11
15
  const contract = new ethers_1.ethers.Contract(gasRegistryContractAddress, GasRegistry_json_1.default, signer);
12
16
  // Each TG costs 0.001 ETH, so calculate the ETH required for the given TG amount
13
- const amountInEth = tgAmount * 0.001;
14
- const amountInEthWei = ethers_1.ethers.parseEther(amountInEth.toString());
17
+ const amountInEthWei = tgAmount;
18
+ // const amountInEthWei = ethers.parseEther(amountInEth.toString());
15
19
  const tx = await contract.purchaseTG(amountInEthWei, { value: amountInEthWei });
16
20
  await tx.wait();
17
21
  return tx;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.withdrawTg = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const GasRegistry_json_1 = __importDefault(require("../contracts/abi/GasRegistry.json"));
9
+ const config_1 = require("../config");
9
10
  /**
10
11
  * Withdraw ETH in exchange for TG tokens.
11
12
  * @param signer ethers.Signer instance
@@ -13,9 +14,12 @@ const GasRegistry_json_1 = __importDefault(require("../contracts/abi/GasRegistry
13
14
  * @returns The transaction object
14
15
  */
15
16
  const withdrawTg = async (signer, amountTG) => {
16
- const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS || '0x204F9278D6BB7714D7A40842423dFd5A27cC1b88';
17
+ const network = await signer.provider?.getNetwork();
18
+ const chainId = network?.chainId ? network.chainId.toString() : undefined;
19
+ const { gasRegistry } = (0, config_1.getChainAddresses)(chainId);
20
+ const gasRegistryContractAddress = gasRegistry;
17
21
  if (!gasRegistryContractAddress) {
18
- throw new Error('GAS_REGISTRY_CONTRACT_ADDRESS is not set in the environment variables');
22
+ throw new Error('GasRegistry address not configured for this chain. Update config mapping.');
19
23
  }
20
24
  const contract = new ethers_1.ethers.Contract(gasRegistryContractAddress, GasRegistry_json_1.default, signer);
21
25
  // Assumes the contract has a function: claimEthForTg(uint256 amount)
package/dist/client.js CHANGED
@@ -10,7 +10,7 @@ class TriggerXClient {
10
10
  this.apiKey = apiKey; // Initialize the apiKey
11
11
  // const baseConfig = getConfig();
12
12
  this.client = axios_1.default.create({
13
- baseURL: 'https://data.triggerx.network',
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
15
  ...config,
16
16
  });
package/dist/config.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  export interface SDKConfig {
2
2
  apiKey: string;
3
3
  apiUrl: string;
4
- contractAddress: string;
5
4
  }
5
+ export declare const CONTRACT_ADDRESSES_BY_CHAIN: Record<string, {
6
+ gasRegistry: string;
7
+ jobRegistry: string;
8
+ }>;
6
9
  export declare function getConfig(): SDKConfig;
10
+ export declare function getChainAddresses(chainId: string | number | undefined): {
11
+ gasRegistry: string;
12
+ jobRegistry: string;
13
+ };
package/dist/config.js CHANGED
@@ -2,11 +2,35 @@
2
2
  // import dotenv from 'dotenv';
3
3
  // dotenv.config();
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.CONTRACT_ADDRESSES_BY_CHAIN = void 0;
5
6
  exports.getConfig = getConfig;
7
+ exports.getChainAddresses = getChainAddresses;
8
+ // Contract addresses per chain
9
+ // Keyed by chainId as string to avoid bigint conversions throughout the SDK
10
+ exports.CONTRACT_ADDRESSES_BY_CHAIN = {
11
+ // OP Sepolia? (used in examples) 11155420 - preserves previous defaults
12
+ '11155420': {
13
+ gasRegistry: '0x204F9278D6BB7714D7A40842423dFd5A27cC1b88',
14
+ jobRegistry: '0x476ACc7949a95e31144cC84b8F6BC7abF0967E4b',
15
+ },
16
+ // Arbitrum One (42161)
17
+ '42161': {
18
+ gasRegistry: '0x93dDB2307F3Af5df85F361E5Cddd898Acd3d132d',
19
+ jobRegistry: '0xAf1189aFd1F1880F09AeC3Cbc32cf415c735C710',
20
+ },
21
+ // Default/fallbacks can be extended as needed for other networks
22
+ };
6
23
  function getConfig() {
7
24
  return {
8
- apiKey: process.env.API_KEY || '',
9
- apiUrl: process.env.API_URL || '',
10
- contractAddress: process.env.CONTRACT_ADDRESS || '',
25
+ apiKey: '',
26
+ apiUrl: '',
27
+ };
28
+ }
29
+ function getChainAddresses(chainId) {
30
+ const chainKey = String(chainId ?? '');
31
+ const mapped = exports.CONTRACT_ADDRESSES_BY_CHAIN[chainKey];
32
+ return {
33
+ gasRegistry: mapped ? mapped.gasRegistry : '',
34
+ jobRegistry: mapped ? mapped.jobRegistry : '',
11
35
  };
12
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdk-triggerx",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
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",
@@ -15,7 +15,13 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/trigg3rX/triggerx-newSDK.git"
17
17
  },
18
- "keywords": ["triggerx", "sdk", "web3", "blockchain", "ethers"],
18
+ "keywords": [
19
+ "triggerx",
20
+ "sdk",
21
+ "web3",
22
+ "blockchain",
23
+ "ethers"
24
+ ],
19
25
  "directories": {
20
26
  "test": "test"
21
27
  },