sdk-triggerx 0.1.6 → 0.1.7

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/dist/{src/api → api}/jobs.js +0 -3
  2. package/dist/{src/config.js → config.js} +5 -0
  3. package/package.json +15 -12
  4. package/.eslintrc.json +0 -16
  5. package/dist/test/createJobExample.d.ts +0 -1
  6. package/dist/test/createJobExample.js +0 -84
  7. package/dist/test/deleteJob.test.d.ts +0 -1
  8. package/dist/test/deleteJob.test.js +0 -22
  9. package/dist/test/example.test.d.ts +0 -1
  10. package/dist/test/example.test.js +0 -11
  11. package/dist/test/getJobDataById.test.d.ts +0 -1
  12. package/dist/test/getJobDataById.test.js +0 -23
  13. package/dist/test/getUserData.test.d.ts +0 -1
  14. package/dist/test/getUserData.test.js +0 -22
  15. package/dist/test/getjob.test.d.ts +0 -1
  16. package/dist/test/getjob.test.js +0 -21
  17. package/dist/test/testTgFunctions.d.ts +0 -1
  18. package/dist/test/testTgFunctions.js +0 -56
  19. package/jest.config.js +0 -7
  20. package/scripts/deploy.ts +0 -9
  21. package/src/api/checkTgBalance.ts +0 -27
  22. package/src/api/deleteJob.ts +0 -22
  23. package/src/api/getJobDataById.ts +0 -24
  24. package/src/api/getUserData.ts +0 -24
  25. package/src/api/getjob.ts +0 -26
  26. package/src/api/jobs.ts +0 -352
  27. package/src/api/topupTg.ts +0 -17
  28. package/src/api/withdrawTg.ts +0 -25
  29. package/src/client.ts +0 -38
  30. package/src/config.ts +0 -13
  31. package/src/contracts/JobRegistry.ts +0 -45
  32. package/src/contracts/TriggerXContract.ts +0 -14
  33. package/src/contracts/abi/.gitkeep +0 -1
  34. package/src/contracts/abi/GasRegistry.json +0 -607
  35. package/src/contracts/abi/JobRegistry.json +0 -1554
  36. package/src/contracts/index.ts +0 -1
  37. package/src/index.ts +0 -7
  38. package/src/types.ts +0 -249
  39. package/src/utils/errors.ts +0 -13
  40. package/test/createJobExample.ts +0 -91
  41. package/test/deleteJob.test.ts +0 -25
  42. package/test/example.test.d.ts +0 -1
  43. package/test/example.test.js +0 -11
  44. package/test/example.test.ts +0 -10
  45. package/test/getJobDataById.test.ts +0 -27
  46. package/test/getUserData.test.ts +0 -25
  47. package/test/getjob.test.ts +0 -23
  48. package/test/testTgFunctions.ts +0 -56
  49. package/tsconfig.json +0 -16
  50. /package/dist/{src/api → api}/checkTgBalance.d.ts +0 -0
  51. /package/dist/{src/api → api}/checkTgBalance.js +0 -0
  52. /package/dist/{src/api → api}/deleteJob.d.ts +0 -0
  53. /package/dist/{src/api → api}/deleteJob.js +0 -0
  54. /package/dist/{src/api → api}/getJobDataById.d.ts +0 -0
  55. /package/dist/{src/api → api}/getJobDataById.js +0 -0
  56. /package/dist/{src/api → api}/getUserData.d.ts +0 -0
  57. /package/dist/{src/api → api}/getUserData.js +0 -0
  58. /package/dist/{src/api → api}/getjob.d.ts +0 -0
  59. /package/dist/{src/api → api}/getjob.js +0 -0
  60. /package/dist/{src/api → api}/jobs.d.ts +0 -0
  61. /package/dist/{src/api → api}/topupTg.d.ts +0 -0
  62. /package/dist/{src/api → api}/topupTg.js +0 -0
  63. /package/dist/{src/api → api}/withdrawTg.d.ts +0 -0
  64. /package/dist/{src/api → api}/withdrawTg.js +0 -0
  65. /package/dist/{src/client.d.ts → client.d.ts} +0 -0
  66. /package/dist/{src/client.js → client.js} +0 -0
  67. /package/dist/{src/config.d.ts → config.d.ts} +0 -0
  68. /package/dist/{src/contracts → contracts}/JobRegistry.d.ts +0 -0
  69. /package/dist/{src/contracts → contracts}/JobRegistry.js +0 -0
  70. /package/dist/{src/contracts → contracts}/TriggerXContract.d.ts +0 -0
  71. /package/dist/{src/contracts → contracts}/TriggerXContract.js +0 -0
  72. /package/dist/{src/contracts → contracts}/abi/GasRegistry.json +0 -0
  73. /package/dist/{src/contracts → contracts}/abi/JobRegistry.json +0 -0
  74. /package/dist/{src/contracts → contracts}/index.d.ts +0 -0
  75. /package/dist/{src/contracts → contracts}/index.js +0 -0
  76. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  77. /package/dist/{src/index.js → index.js} +0 -0
  78. /package/dist/{src/types.d.ts → types.d.ts} +0 -0
  79. /package/dist/{src/types.js → types.js} +0 -0
  80. /package/dist/{src/utils → utils}/errors.d.ts +0 -0
  81. /package/dist/{src/utils → utils}/errors.js +0 -0
package/src/api/jobs.ts DELETED
@@ -1,352 +0,0 @@
1
- import { TriggerXClient } from '../client';
2
- import {
3
- TimeBasedJobInput,
4
- EventBasedJobInput,
5
- ConditionBasedJobInput,
6
- CreateJobData,
7
- JobResponse,
8
- } from '../types';
9
- import { createJobOnChain } from '../contracts/JobRegistry';
10
- import { ethers, Signer } from 'ethers';
11
- import jobRegistryAbi from '../contracts/abi/JobRegistry.json';
12
- import { topupTg } from './topupTg';
13
- import { checkTgBalance } from './checkTgBalance';
14
- const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
15
- const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
16
- const JOB_REGISTRY_ADDRESS = '0xdB66c11221234C6B19cCBd29868310c31494C21C'; // Set your fixed contract address here
17
-
18
- export function toCreateJobDataFromTime(
19
- input: TimeBasedJobInput,
20
- balances: { etherBalance: bigint; tokenBalanceWei: bigint },
21
- userAddress: string,
22
- jobCostPrediction: number,
23
- ): CreateJobData {
24
- return {
25
- job_id: JOB_ID,
26
- user_address: userAddress,
27
- ether_balance: balances.etherBalance,
28
- token_balance: balances.tokenBalanceWei,
29
- job_title: input.jobTitle,
30
- task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
31
- custom: true,
32
- time_frame: input.timeFrame,
33
- recurring: false,
34
- job_cost_prediction: jobCostPrediction,
35
- timezone: input.timezone,
36
- created_chain_id: input.chainId,
37
- schedule_type: input.scheduleType,
38
- time_interval: input.scheduleType === 'interval' ? input.timeInterval : undefined,
39
- cron_expression: input.scheduleType === 'cron' ? input.cronExpression : undefined,
40
- specific_schedule: input.scheduleType === 'specific' ? input.specificSchedule : undefined,
41
- target_chain_id: input.chainId,
42
- target_contract_address: input.targetContractAddress,
43
- target_function: input.targetFunction,
44
- abi: input.abi,
45
- arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
46
- arguments: input.arguments,
47
- dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
48
- is_imua: input.isImua ?? true,
49
- };
50
- }
51
-
52
- export function toCreateJobDataFromEvent(
53
- input: EventBasedJobInput,
54
- balances: { etherBalance: bigint; tokenBalanceWei: bigint },
55
- userAddress: string,
56
- jobCostPrediction: number,
57
- ): CreateJobData {
58
- return {
59
- job_id: JOB_ID,
60
- user_address: userAddress,
61
- ether_balance: balances.etherBalance,
62
- token_balance: balances.tokenBalanceWei,
63
- job_title: input.jobTitle,
64
- task_definition_id: input.dynamicArgumentsScriptUrl ? 4 : 3,
65
- custom: true,
66
- time_frame: input.timeFrame,
67
- recurring: input.recurring ?? false,
68
- job_cost_prediction: jobCostPrediction,
69
- timezone: input.timezone,
70
- created_chain_id: input.chainId,
71
- trigger_chain_id: (input as any).triggerChainId ?? input.chainId,
72
- trigger_contract_address: input.triggerContractAddress,
73
- trigger_event: input.triggerEvent,
74
- target_chain_id: input.chainId,
75
- target_contract_address: input.targetContractAddress,
76
- target_function: input.targetFunction,
77
- abi: input.abi,
78
- arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
79
- arguments: input.arguments,
80
- dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
81
- is_imua: input.isImua ?? true,
82
- };
83
- }
84
-
85
- export function toCreateJobDataFromCondition(
86
- input: ConditionBasedJobInput,
87
- balances: { etherBalance: bigint; tokenBalanceWei: bigint },
88
- userAddress: string,
89
- jobCostPrediction: number,
90
- ): CreateJobData {
91
- return {
92
- job_id: JOB_ID,
93
- user_address: userAddress,
94
- ether_balance: balances.etherBalance,
95
- token_balance: balances.tokenBalanceWei,
96
- job_title: input.jobTitle,
97
- task_definition_id: input.dynamicArgumentsScriptUrl ? 6 : 5,
98
- custom: true,
99
- time_frame: input.timeFrame,
100
- recurring: input.recurring ?? false,
101
- job_cost_prediction: jobCostPrediction,
102
- timezone: input.timezone,
103
- created_chain_id: input.chainId,
104
- condition_type: input.conditionType,
105
- upper_limit: input.upperLimit,
106
- lower_limit: input.lowerLimit,
107
- value_source_type: input.valueSourceType,
108
- value_source_url: input.valueSourceUrl,
109
- target_chain_id: input.chainId,
110
- target_contract_address: input.targetContractAddress,
111
- target_function: input.targetFunction,
112
- abi: input.abi,
113
- arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
114
- arguments: input.arguments,
115
- dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
116
- is_imua: input.isImua ?? true,
117
- };
118
- }
119
-
120
- // --- Encoding helpers for different job types ---
121
- function encodeJobType1Data(timeInterval: number) {
122
- return ethers.AbiCoder.defaultAbiCoder().encode(
123
- ['uint256'],
124
- [timeInterval]
125
- );
126
- }
127
-
128
- function encodeJobType2Data(timeInterval: number, ipfsHash: string) {
129
- return ethers.AbiCoder.defaultAbiCoder().encode(
130
- ['uint256', 'bytes32'],
131
- [timeInterval, ipfsHash]
132
- );
133
- }
134
-
135
- function encodeJobType3or5Data(recurringJob: boolean) {
136
- return ethers.AbiCoder.defaultAbiCoder().encode(
137
- ['bool'],
138
- [recurringJob]
139
- );
140
- }
141
-
142
- function encodeJobType4or6Data(recurringJob: boolean, ipfsHash: string) {
143
- return ethers.AbiCoder.defaultAbiCoder().encode(
144
- ['bool', 'bytes32'],
145
- [recurringJob, ipfsHash]
146
- );
147
- }
148
-
149
- export interface CreateJobParams {
150
- jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput;
151
- signer: Signer;
152
- encodedData?: string;
153
- }
154
-
155
- /**
156
- * Create a job on the blockchain.
157
- * @param client TriggerXClient instance
158
- * @param params Parameters for creating the job
159
- * @returns JobResponse containing the result of the job creation
160
- */
161
- export async function createJob(
162
- client: TriggerXClient,
163
- params: CreateJobParams
164
- ): Promise<JobResponse> {
165
- let { jobInput, signer, encodedData } = params;
166
-
167
- if (!signer) {
168
- throw new Error('A valid ethers.Signer must be provided to createJob');
169
- }
170
-
171
- // Use the API key from the client instance
172
- const apiKey = client.getApiKey();
173
-
174
- const userAddress = await signer.getAddress();
175
-
176
- let jobTitle: string, timeFrame: number, targetContractAddress: string, jobType: number;
177
- if ('jobTitle' in jobInput) jobTitle = jobInput.jobTitle;
178
- if ('timeFrame' in jobInput) timeFrame = jobInput.timeFrame;
179
- if ('targetContractAddress' in jobInput) targetContractAddress = jobInput.targetContractAddress;
180
-
181
- // Validate schedule-specific fields for time-based jobs
182
- if ('scheduleType' in jobInput) {
183
- if (jobInput.scheduleType === 'interval' && (jobInput.timeInterval === undefined || jobInput.timeInterval === null)) {
184
- throw new Error('timeInterval is required when scheduleType is interval');
185
- }
186
- if (jobInput.scheduleType === 'cron' && !jobInput.cronExpression) {
187
- throw new Error('cronExpression is required when scheduleType is cron');
188
- }
189
- if (jobInput.scheduleType === 'specific' && !jobInput.specificSchedule) {
190
- throw new Error('specificSchedule is required when scheduleType is specific');
191
- }
192
- }
193
-
194
- // Infer jobType from jobInput
195
- if ('scheduleType' in jobInput) {
196
- jobType = jobInput.dynamicArgumentsScriptUrl ? 2 : 1; // Time-based job
197
- } else if ('triggerChainId' in jobInput) {
198
- jobType = jobInput.dynamicArgumentsScriptUrl ? 4 : 3; // Event-based job
199
- } else {
200
- jobType = jobInput.dynamicArgumentsScriptUrl ? 6 : 5; // Condition-based job
201
- }
202
-
203
- // --- Generate encodedData if not provided ---
204
- if (!encodedData) {
205
- // Time-based jobs
206
- if ('scheduleType' in jobInput) {
207
- if (jobType === 1) {
208
- encodedData = encodeJobType1Data(jobInput.timeInterval ?? 0);
209
- } else if (jobType === 2) {
210
- encodedData = encodeJobType2Data(jobInput.timeInterval ?? 0, jobInput.dynamicArgumentsScriptUrl || '');
211
- }
212
- }
213
- // Event-based jobs
214
- else if ('triggerChainId' in jobInput) {
215
- if (jobType === 3 || jobType === 5) {
216
- encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
217
- } else if (jobType === 4 || jobType === 6) {
218
- encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
219
- }
220
- }
221
- // Condition-based jobs
222
- else {
223
- if (jobType === 3 || jobType === 5) {
224
- encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
225
- } else if (jobType === 4 || jobType === 6) {
226
- encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
227
- }
228
- }
229
- }
230
-
231
- // Handle job_cost_prediction logic based on argType (static/dynamic)
232
- // If static, set to 0.1. If dynamic, call backend API to get fee and ask user to proceed.
233
-
234
- // Determine argType directly from user input
235
- let argType: number = 1; // default to static
236
- if ('argType' in jobInput) {
237
- if (jobInput.argType === 'dynamic' || jobInput.argType === 2) {
238
- argType = 2;
239
- } else {
240
- argType = 1;
241
- }
242
- }
243
-
244
- //if jobis time based then check the no of executions of the job from time frame and time interval by deviding time frame by time interval
245
- let noOfExecutions: number = 1;
246
- if ('scheduleType' in jobInput) {
247
- noOfExecutions = jobInput.timeFrame / (jobInput.timeInterval ?? 0);
248
- }
249
-
250
- // Set job_cost_prediction
251
- let job_cost_prediction: number = 0.1 * noOfExecutions; // default for static
252
-
253
- if (argType === 2) {
254
- // Dynamic: call backend API to get fee
255
- const ipfs_url = jobInput.dynamicArgumentsScriptUrl;
256
- if (!ipfs_url) {
257
- throw new Error('dynamicArgumentsScriptUrl is required for dynamic argType');
258
- }
259
-
260
-
261
- // Call backend API to get fee
262
- let fee: number = 0;
263
- try {
264
- const feeRes = await client.get<any>(
265
- '/api/fees',
266
- { params: { ipfs_url } }
267
- );
268
- // The API now returns { total_fee: number }
269
- if (feeRes && typeof feeRes.total_fee === 'number') {
270
- fee = feeRes.total_fee;
271
- } else if (feeRes && feeRes.data && typeof feeRes.data.total_fee === 'number') {
272
- fee = feeRes.data.total_fee;
273
- } else {
274
- throw new Error('Invalid response from /api/fees: missing total_fee');
275
- }
276
- } catch (err) {
277
- throw new Error('Failed to fetch job cost prediction: ' + (err as Error).message);
278
- }
279
- job_cost_prediction = fee * noOfExecutions;
280
- }
281
- // Ask user if they want to proceed
282
- // Since this is a library, we can't prompt in Node.js directly.
283
- // We'll throw an error with the fee and let the caller handle the prompt/confirmation.
284
- // If you want to automate, you can add a `proceed` flag to params in the future.
285
-
286
- // Check if the user has enough TG to cover the job cost prediction
287
- const { tgBalanceWei, tgBalance } = await checkTgBalance(signer);
288
- if (Number(tgBalance) < job_cost_prediction) {
289
- // Check if user has enabled auto topup
290
- // For each job type, autotopupTG should be present in jobInput
291
- const autoTopupTG = (jobInput as any).autotopupTG === true;
292
- if (!autoTopupTG) {
293
- throw new Error(`Insufficient TG balance. Job cost prediction is ${job_cost_prediction}. Current TG balance: ${tgBalance}. Please set autotopupTG: true in jobInput.`);
294
- } else {
295
- // autotopupTG is true, automatically top up
296
- const requiredTG = Math.ceil(job_cost_prediction * 1000); // 1 TG = 0.001 ETH
297
- await topupTg(requiredTG, signer);
298
- }
299
- }
300
-
301
- // Compute balances to store with the job
302
- const tokenBalanceWei = tgBalanceWei;
303
- const etherBalance = tokenBalanceWei / 1000n;
304
-
305
- // Patch jobInput with job_cost_prediction for downstream usage
306
- (jobInput as any).jobCostPrediction = job_cost_prediction;
307
-
308
- const jobId = await createJobOnChain({
309
- jobTitle: jobTitle!,
310
- jobType,
311
- timeFrame: timeFrame!,
312
- targetContractAddress: targetContractAddress!,
313
- encodedData: encodedData || '',
314
- contractAddress: JOB_REGISTRY_ADDRESS,
315
- abi: jobRegistryAbi.abi,
316
- signer,
317
- });
318
-
319
- // 2. Convert input to CreateJobData
320
- let jobData: CreateJobData;
321
- const balances = { etherBalance, tokenBalanceWei };
322
- if ('scheduleType' in jobInput) {
323
- jobData = toCreateJobDataFromTime(jobInput as TimeBasedJobInput, balances, userAddress, job_cost_prediction);
324
- } else if ('triggerChainId' in jobInput) {
325
- jobData = toCreateJobDataFromEvent(jobInput as EventBasedJobInput, balances, userAddress, job_cost_prediction);
326
- } else {
327
- jobData = toCreateJobDataFromCondition(jobInput as ConditionBasedJobInput, balances, userAddress, job_cost_prediction);
328
- }
329
- // 3. Set the job_id from contract
330
- jobData.job_id = jobId;
331
-
332
- // 4. Call the API
333
- try {
334
- // Ensure JSON-serializable payload (use numbers for balances)
335
- const jobDataForApi = {
336
- ...jobData,
337
- ether_balance: typeof jobData.ether_balance === 'bigint' ? Number(jobData.ether_balance) : Number(jobData.ether_balance),
338
- token_balance: typeof jobData.token_balance === 'bigint' ? Number(jobData.token_balance) : Number(jobData.token_balance),
339
- } as any;
340
-
341
- const res = await client.post<any>(
342
- '/api/jobs',
343
- [jobDataForApi],
344
- {
345
- headers: { 'Content-Type': 'application/json', 'X-API-KEY': apiKey },
346
- }
347
- );
348
- return { success: true, data: res };
349
- } catch (error) {
350
- return { success: false, error: (error as Error).message };
351
- }
352
- }
@@ -1,17 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import gasRegistryAbi from '../contracts/abi/GasRegistry.json';
3
-
4
- export const topupTg = async (tgAmount: number, signer: ethers.Signer) => {
5
- const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS as string || '0x85ea3eB894105bD7e7e2A8D34cf66C8E8163CD2a';
6
- const contract = new ethers.Contract(gasRegistryContractAddress, gasRegistryAbi, signer);
7
-
8
- // Each TG costs 0.001 ETH, so calculate the ETH required for the given TG amount
9
- const amountInEth = tgAmount * 0.001;
10
- const amountInEthWei = ethers.parseEther(amountInEth.toString());
11
- const tx = await contract.purchaseTG(
12
- amountInEthWei,
13
- { value: amountInEthWei }
14
- );
15
- await tx.wait();
16
- return tx;
17
- };
@@ -1,25 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import gasRegistryAbi from '../contracts/abi/GasRegistry.json';
3
-
4
- /**
5
- * Withdraw ETH in exchange for TG tokens.
6
- * @param signer ethers.Signer instance
7
- * @param amountTG The amount of TG tokens to withdraw (as a string or BigNumberish)
8
- * @returns The transaction object
9
- */
10
- export const withdrawTg = async (
11
- signer: ethers.Signer,
12
- amountTG: string | ethers.BigNumberish
13
- ) => {
14
- const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS as string || '0x85ea3eB894105bD7e7e2A8D34cf66C8E8163CD2a';
15
- if (!gasRegistryContractAddress) {
16
- throw new Error('GAS_REGISTRY_CONTRACT_ADDRESS is not set in the environment variables');
17
- }
18
- const contract = new ethers.Contract(gasRegistryContractAddress, gasRegistryAbi, signer);
19
-
20
- // Assumes the contract has a function: claimEthForTg(uint256 amount)
21
- const amountTGWei = ethers.parseEther(amountTG.toString());
22
- const tx = await contract.claimETHForTG(amountTGWei);
23
- await tx.wait();
24
- return tx;
25
- };
package/src/client.ts DELETED
@@ -1,38 +0,0 @@
1
- import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
2
- import { getConfig } from './config';
3
-
4
- export class TriggerXClient {
5
- private client: AxiosInstance;
6
- private apiKey: string; // Store the API key
7
-
8
- constructor(apiKey: string, config?: AxiosRequestConfig) {
9
- this.apiKey = apiKey; // Initialize the apiKey
10
- const baseConfig = getConfig();
11
- this.client = axios.create({
12
- baseURL: config?.baseURL || baseConfig.apiUrl || 'https://data.triggerx.network', //http://localhost:9002 , https://data.triggerx.network
13
- headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
14
- ...config,
15
- });
16
- }
17
-
18
- // Method to get the API key
19
- getApiKey(): string {
20
- return this.apiKey;
21
- }
22
-
23
- async get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
24
- const response = await this.client.get<T>(url, config);
25
- return response.data;
26
- }
27
-
28
- async post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
29
- const response = await this.client.post<T>(url, data, config);
30
- return response.data;
31
- }
32
-
33
- // New PUT method
34
- async put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
35
- const response = await this.client.put<T>(url, data, config);
36
- return response.data;
37
- }
38
- }
package/src/config.ts DELETED
@@ -1,13 +0,0 @@
1
- export interface SDKConfig {
2
- apiKey: string;
3
- apiUrl: string;
4
- contractAddress: string;
5
- }
6
-
7
- export function getConfig(): SDKConfig {
8
- return {
9
- apiKey: process.env.API_KEY || '',
10
- apiUrl: process.env.API_URL || '',
11
- contractAddress: process.env.CONTRACT_ADDRESS || '',
12
- };
13
- }
@@ -1,45 +0,0 @@
1
- import { ethers, Signer } from 'ethers';
2
-
3
- export interface CreateJobOnChainParams {
4
- jobTitle: string;
5
- jobType: number;
6
- timeFrame: number;
7
- targetContractAddress: string;
8
- encodedData: string;
9
- contractAddress: string;
10
- abi: any;
11
- signer: Signer;
12
- }
13
-
14
- export async function createJobOnChain({
15
- jobTitle,
16
- jobType,
17
- timeFrame,
18
- targetContractAddress,
19
- encodedData,
20
- contractAddress,
21
- abi,
22
- signer,
23
- }: CreateJobOnChainParams): Promise<string> {
24
- const contract = new ethers.Contract(contractAddress, abi, signer);
25
-
26
- const tx = await contract.createJob(jobTitle, jobType, timeFrame, targetContractAddress, encodedData);
27
- const receipt = await tx.wait();
28
-
29
- // Try to extract jobId from event logs (assume event is JobCreated(jobId,...))
30
- const event = receipt.logs
31
- .map((log: any) => {
32
- try {
33
- return contract.interface.parseLog(log);
34
- } catch {
35
- return null;
36
- }
37
- })
38
- .find((e: any) => e && e.name === 'JobCreated');
39
-
40
- if (event && event.args && event.args[0]) {
41
- return event.args[0].toString();
42
- }
43
-
44
- throw new Error('Job ID not found in contract events');
45
- }
@@ -1,14 +0,0 @@
1
- import { Contract, Provider } from 'ethers';
2
-
3
- export class TriggerXContract {
4
- private contract: Contract;
5
-
6
- constructor(address: string, abi: any, provider: Provider) {
7
- this.contract = new Contract(address, abi, provider);
8
- }
9
-
10
- async getTaskCount(): Promise<number> {
11
- // Placeholder for contract call
12
- return this.contract.taskCount();
13
- }
14
- }
@@ -1 +0,0 @@
1
-