sdk-triggerx 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -31,11 +31,10 @@ npm install sdk-triggerx
31
31
  import { TriggerXClient } from 'sdk-triggerx';
32
32
 
33
33
  const client = new TriggerXClient('YOUR_API_KEY');
34
-
35
- //👉 To get your API key, visit: [https://app.triggerx.network/generate-api](https://app.triggerx.network/generate-api)
36
-
37
34
  ```
38
35
 
36
+ - To get your API key, visit: [Generate API Key](https://app.triggerx.network/generate-api)
37
+
39
38
  ---
40
39
 
41
40
  ### 2. Create a Job
@@ -51,6 +50,16 @@ const client = new TriggerXClient('YOUR_API_KEY');
51
50
  - `ArgType.Static`: Hardcoded values
52
51
  - `ArgType.Dynamic`: Runtime values fetched from a script
53
52
 
53
+ #### Supported Condition Types (for `conditionType`)
54
+
55
+ - `greater_than`
56
+ - `less_than`
57
+ - `between`
58
+ - `equals`
59
+ - `not_equals`
60
+ - `greater_equal`
61
+ - `less_equal`
62
+
54
63
  ---
55
64
 
56
65
  #### 🕒 Example: Time-based Static Job
@@ -59,27 +68,26 @@ const client = new TriggerXClient('YOUR_API_KEY');
59
68
  import { createJob, JobType, ArgType } from 'sdk-triggerx';
60
69
 
61
70
  const jobInput = {
62
- jobType: JobType.Time,
63
- argType: ArgType.Static,
64
- jobTitle: 'My Time Job',
65
- timeFrame: 36,
66
- scheduleType: 'interval',
67
- timeInterval: 33,
68
- cronExpression: '0 0 * * *',
69
- specificSchedule: '2025-01-01 00:00:00',
70
- timezone: 'Asia/Calcutta',
71
- recurring: false,
72
- jobCostPrediction: 0.1,
73
- createdChainId: '11155420',
74
- targetChainId: '11155420',
75
- targetContractAddress: '0x...',
76
- targetFunction: 'incrementBy',
77
- abi: '[...]',
78
- isImua: true,
79
- arguments: ['3'],
80
- dynamicArgumentsScriptUrl: '',
81
- // if more TG needed auto top-up TG must true for automatially top up TG
82
- autotopupTG: true,
71
+ jobType: JobType.Time, // Job type discriminator
72
+ argType: ArgType.Static, // Static or Dynamic arguments
73
+
74
+ jobTitle: 'My Time Job', // Human-readable job title
75
+ timeFrame: 36, // Duration the job stays active (seconds)
76
+ scheduleType: 'interval', // 'interval' | 'cron' | 'specific'
77
+ timeInterval: 33, // Required if scheduleType = 'interval' (seconds)
78
+ // cronExpression: '0 0 * * *', // Required if scheduleType = 'cron' (CRON string)
79
+ // specificSchedule: '2025-01-01 00:00:00', // Required if scheduleType = 'specific' (datetime)
80
+ timezone: 'Asia/Calcutta', // IANA timezone for scheduling
81
+
82
+ chainId: '11155420', // EVM chain for creation/target
83
+ targetContractAddress: '0x...', // Target contract to call
84
+ targetFunction: 'incrementBy', // Target function name
85
+ abi: '[...]', // JSON ABI string for target contract
86
+
87
+ isImua: false, // Optional feature flag
88
+ arguments: ['3'], // Target function args as strings
89
+ dynamicArgumentsScriptUrl: '', // If ArgType.Dynamic, provide IPFS/URL here
90
+ autotopupTG: true, // Auto top-up TG if balance is low
83
91
  };
84
92
 
85
93
  const signer = /* ethers.Signer instance */;
@@ -93,25 +101,27 @@ console.log(result);
93
101
 
94
102
  ```ts
95
103
  const jobInput = {
96
- jobType: JobType.Event,
97
- argType: ArgType.Dynamic,
98
- jobTitle: 'My Event Job',
99
- timeFrame: 36,
100
- recurring: true,
101
- jobCostPrediction: 0.2,
102
- timezone: 'Asia/Calcutta',
103
- createdChainId: '11155420',
104
- triggerChainId: '11155420',
105
- triggerContractAddress: '0x...',
106
- triggerEvent: 'CounterIncremented',
107
- targetChainId: '11155420',
108
- targetContractAddress: '0x...',
109
- targetFunction: 'incrementBy',
110
- abi: '[...]',
111
- arguments: [],
112
- dynamicArgumentsScriptUrl: 'https://your-ipfs-url',
113
- isImua: true,
114
- autotopupTG: true,
104
+ jobType: JobType.Event, // Job type discriminator
105
+ argType: ArgType.Dynamic, // Dynamic arguments fetched via script
106
+
107
+ jobTitle: 'My Event Job', // Human-readable job title
108
+ timeFrame: 36, // Duration the job stays active (seconds)
109
+ recurring: true, // Whether the event job recurs
110
+ timezone: 'Asia/Calcutta', // IANA timezone (for metadata)
111
+
112
+ chainId: '11155420', // EVM chain for creation/target
113
+ triggerChainId: '11155420', // Chain where the event is emitted
114
+ triggerContractAddress: '0x...', // Event-emitting contract address
115
+ triggerEvent: 'CounterIncremented', // Event name to watch
116
+
117
+ targetContractAddress: '0x...', // Target contract to call
118
+ targetFunction: 'incrementBy', // Target function name
119
+ abi: '[...]', // JSON ABI for target contract
120
+
121
+ arguments: [], // Target function args as strings
122
+ dynamicArgumentsScriptUrl: 'https://your-ipfs-url', // Script URL for dynamic args
123
+ isImua: false, // Optional feature flag
124
+ autotopupTG: true, // Auto top-up TG if balance is low
115
125
  };
116
126
 
117
127
  const result = await createJob(client, { jobInput, signer });
@@ -124,27 +134,29 @@ console.log(result);
124
134
 
125
135
  ```ts
126
136
  const jobInput = {
127
- jobType: JobType.Condition,
128
- argType: ArgType.Static,
129
- jobTitle: 'My Condition Job',
130
- timeFrame: 36,
131
- recurring: false,
132
- jobCostPrediction: 0.3,
133
- timezone: 'Asia/Calcutta',
134
- createdChainId: '11155420',
135
- conditionType: 'greaterThan',
136
- upperLimit: 100,
137
- lowerLimit: 10,
138
- valueSourceType: 'api',
139
- valueSourceUrl: 'https://api.example.com/value',
140
- targetChainId: '11155420',
141
- targetContractAddress: '0x...',
142
- targetFunction: 'incrementBy',
143
- abi: '[...]',
144
- arguments: ['5'],
145
- dynamicArgumentsScriptUrl: '',
146
- isImua: true,
147
- autotopupTG: true,
137
+ jobType: JobType.Condition, // Job type discriminator
138
+ argType: ArgType.Static, // Static arguments
139
+
140
+ jobTitle: 'My Condition Job', // Human-readable job title
141
+ timeFrame: 36, // Duration the job stays active (seconds)
142
+ recurring: false, // Whether the condition job recurs
143
+ timezone: 'Asia/Calcutta', // IANA timezone (for metadata)
144
+
145
+ chainId: '11155420', // EVM chain for creation/target
146
+ conditionType: 'greater_than', // One of the supported condition types 'greater_than' | 'less_than' |'between' | 'equals' | 'not_equals' | 'greater_equal' | 'less_equal'
147
+ upperLimit: 100, // Upper threshold
148
+ lowerLimit: 10, // Lower threshold
149
+ valueSourceType: 'api', // 'api'
150
+ valueSourceUrl: 'https://api.example.com/value', // Source URL for condition
151
+
152
+ targetContractAddress: '0x...', // Target contract to call
153
+ targetFunction: 'incrementBy', // Target function name
154
+ abi: '[...]', // JSON ABI for target contract
155
+
156
+ arguments: ['5'], // Target function args as strings
157
+ dynamicArgumentsScriptUrl: '', // If ArgType.Dynamic, provide IPFS/URL here
158
+ isImua: false, // Optional feature flag
159
+ autotopupTG: true, // Auto top-up TG if balance is low
148
160
  };
149
161
 
150
162
  const result = await createJob(client, { jobInput, signer });
@@ -216,22 +228,6 @@ Includes:
216
228
 
217
229
  ---
218
230
 
219
- ## 🗂️ Project Structure
220
-
221
- ```
222
- sdk-triggerx/
223
- ├── index.ts # Entry point
224
- ├── client.ts # Axios client wrapper
225
- ├── config.ts # Config and environment loader
226
- ├── types.ts # Shared interfaces and enums
227
- ├── api/ # Backend API modules
228
- ├── contracts/ # Contract logic and ABIs
229
- ├── utils/ # Error and helper utilities
230
- ├── test/ # Unit/integration tests
231
- └── scripts/ # Example/test scripts
232
- ```
233
-
234
- ---
235
231
 
236
232
  ## ✅ Requirements
237
233
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdk-triggerx",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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",
package/src/api/jobs.ts CHANGED
@@ -19,6 +19,7 @@ export function toCreateJobDataFromTime(
19
19
  input: TimeBasedJobInput,
20
20
  balances: { etherBalance: bigint; tokenBalanceWei: bigint },
21
21
  userAddress: string,
22
+ jobCostPrediction: number,
22
23
  ): CreateJobData {
23
24
  return {
24
25
  job_id: JOB_ID,
@@ -29,15 +30,15 @@ export function toCreateJobDataFromTime(
29
30
  task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
30
31
  custom: true,
31
32
  time_frame: input.timeFrame,
32
- recurring: input.recurring ?? false,
33
- job_cost_prediction: input.jobCostPrediction,
33
+ recurring: false,
34
+ job_cost_prediction: jobCostPrediction,
34
35
  timezone: input.timezone,
35
- created_chain_id: input.createdChainId,
36
+ created_chain_id: input.chainId,
36
37
  schedule_type: input.scheduleType,
37
- time_interval: input.timeInterval,
38
- cron_expression: input.cronExpression,
39
- specific_schedule: input.specificSchedule,
40
- target_chain_id: input.targetChainId,
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,
41
42
  target_contract_address: input.targetContractAddress,
42
43
  target_function: input.targetFunction,
43
44
  abi: input.abi,
@@ -52,6 +53,7 @@ export function toCreateJobDataFromEvent(
52
53
  input: EventBasedJobInput,
53
54
  balances: { etherBalance: bigint; tokenBalanceWei: bigint },
54
55
  userAddress: string,
56
+ jobCostPrediction: number,
55
57
  ): CreateJobData {
56
58
  return {
57
59
  job_id: JOB_ID,
@@ -63,13 +65,13 @@ export function toCreateJobDataFromEvent(
63
65
  custom: true,
64
66
  time_frame: input.timeFrame,
65
67
  recurring: input.recurring ?? false,
66
- job_cost_prediction: input.jobCostPrediction,
68
+ job_cost_prediction: jobCostPrediction,
67
69
  timezone: input.timezone,
68
- created_chain_id: input.createdChainId,
69
- trigger_chain_id: input.triggerChainId,
70
+ created_chain_id: input.chainId,
71
+ trigger_chain_id: (input as any).triggerChainId ?? input.chainId,
70
72
  trigger_contract_address: input.triggerContractAddress,
71
73
  trigger_event: input.triggerEvent,
72
- target_chain_id: input.targetChainId,
74
+ target_chain_id: input.chainId,
73
75
  target_contract_address: input.targetContractAddress,
74
76
  target_function: input.targetFunction,
75
77
  abi: input.abi,
@@ -84,6 +86,7 @@ export function toCreateJobDataFromCondition(
84
86
  input: ConditionBasedJobInput,
85
87
  balances: { etherBalance: bigint; tokenBalanceWei: bigint },
86
88
  userAddress: string,
89
+ jobCostPrediction: number,
87
90
  ): CreateJobData {
88
91
  return {
89
92
  job_id: JOB_ID,
@@ -95,15 +98,15 @@ export function toCreateJobDataFromCondition(
95
98
  custom: true,
96
99
  time_frame: input.timeFrame,
97
100
  recurring: input.recurring ?? false,
98
- job_cost_prediction: input.jobCostPrediction,
101
+ job_cost_prediction: jobCostPrediction,
99
102
  timezone: input.timezone,
100
- created_chain_id: input.createdChainId,
103
+ created_chain_id: input.chainId,
101
104
  condition_type: input.conditionType,
102
105
  upper_limit: input.upperLimit,
103
106
  lower_limit: input.lowerLimit,
104
107
  value_source_type: input.valueSourceType,
105
108
  value_source_url: input.valueSourceUrl,
106
- target_chain_id: input.targetChainId,
109
+ target_chain_id: input.chainId,
107
110
  target_contract_address: input.targetContractAddress,
108
111
  target_function: input.targetFunction,
109
112
  abi: input.abi,
@@ -171,6 +174,19 @@ export async function createJob(
171
174
  if ('timeFrame' in jobInput) timeFrame = jobInput.timeFrame;
172
175
  if ('targetContractAddress' in jobInput) targetContractAddress = jobInput.targetContractAddress;
173
176
 
177
+ // Validate schedule-specific fields for time-based jobs
178
+ if ('scheduleType' in jobInput) {
179
+ if (jobInput.scheduleType === 'interval' && (jobInput.timeInterval === undefined || jobInput.timeInterval === null)) {
180
+ throw new Error('timeInterval is required when scheduleType is interval');
181
+ }
182
+ if (jobInput.scheduleType === 'cron' && !jobInput.cronExpression) {
183
+ throw new Error('cronExpression is required when scheduleType is cron');
184
+ }
185
+ if (jobInput.scheduleType === 'specific' && !jobInput.specificSchedule) {
186
+ throw new Error('specificSchedule is required when scheduleType is specific');
187
+ }
188
+ }
189
+
174
190
  // Infer jobType from jobInput
175
191
  if ('scheduleType' in jobInput) {
176
192
  jobType = jobInput.dynamicArgumentsScriptUrl ? 2 : 1; // Time-based job
@@ -207,6 +223,7 @@ export async function createJob(
207
223
  }
208
224
  }
209
225
  }
226
+
210
227
  // Handle job_cost_prediction logic based on argType (static/dynamic)
211
228
  // If static, set to 0.1. If dynamic, call backend API to get fee and ask user to proceed.
212
229
 
@@ -299,11 +316,11 @@ export async function createJob(
299
316
  let jobData: CreateJobData;
300
317
  const balances = { etherBalance, tokenBalanceWei };
301
318
  if ('scheduleType' in jobInput) {
302
- jobData = toCreateJobDataFromTime(jobInput as TimeBasedJobInput, balances, userAddress);
319
+ jobData = toCreateJobDataFromTime(jobInput as TimeBasedJobInput, balances, userAddress, job_cost_prediction);
303
320
  } else if ('triggerChainId' in jobInput) {
304
- jobData = toCreateJobDataFromEvent(jobInput as EventBasedJobInput, balances, userAddress);
321
+ jobData = toCreateJobDataFromEvent(jobInput as EventBasedJobInput, balances, userAddress, job_cost_prediction);
305
322
  } else {
306
- jobData = toCreateJobDataFromCondition(jobInput as ConditionBasedJobInput, balances, userAddress);
323
+ jobData = toCreateJobDataFromCondition(jobInput as ConditionBasedJobInput, balances, userAddress, job_cost_prediction);
307
324
  }
308
325
  // 3. Set the job_id from contract
309
326
  jobData.job_id = jobId;
package/src/types.ts CHANGED
@@ -33,14 +33,12 @@ export interface TimeBasedJobInput {
33
33
  jobTitle: string;
34
34
  timeFrame: number;
35
35
  scheduleType: 'cron' | 'specific' | 'interval';
36
- timeInterval?: number;
37
- cronExpression?: string;
38
- specificSchedule?: string;
36
+ timeInterval?: number; // required only if scheduleType === 'interval'
37
+ cronExpression?: string; // required only if scheduleType === 'cron'
38
+ specificSchedule?: string; // required only if scheduleType === 'specific'
39
39
  timezone: string;
40
- recurring?: boolean;
41
- jobCostPrediction: number;
42
- createdChainId: string;
43
- targetChainId: string;
40
+ // recurring removed for time-based jobs; always false
41
+ chainId: string; // single chain input; used for created/target
44
42
  targetContractAddress: string;
45
43
  targetFunction: string;
46
44
  abi: string;
@@ -58,9 +56,7 @@ export interface EventBasedJobInput {
58
56
  triggerEvent: string;
59
57
  timezone: string;
60
58
  recurring?: boolean;
61
- jobCostPrediction: number;
62
- createdChainId: string;
63
- targetChainId: string;
59
+ chainId: string; // used for created/trigger/target chains
64
60
  targetContractAddress: string;
65
61
  targetFunction: string;
66
62
  abi: string;
@@ -73,16 +69,14 @@ export interface EventBasedJobInput {
73
69
  export interface ConditionBasedJobInput {
74
70
  jobTitle: string;
75
71
  timeFrame: number;
76
- conditionType: string;
72
+ conditionType: 'greater_than' | 'less_than' | 'between' | 'equals' | 'not_equals' | 'greater_equal' | 'less_equal';
77
73
  upperLimit: number;
78
74
  lowerLimit: number;
79
75
  valueSourceType: string;
80
76
  valueSourceUrl: string;
81
77
  timezone: string;
82
78
  recurring?: boolean;
83
- jobCostPrediction: number;
84
- createdChainId: string;
85
- targetChainId: string;
79
+ chainId: string; // used for created/target chains
86
80
  targetContractAddress: string;
87
81
  targetFunction: string;
88
82
  abi: string;
@@ -4,7 +4,7 @@ import { ethers } from 'ethers';
4
4
 
5
5
  async function main() {
6
6
 
7
- const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
7
+ const apiKey = '';
8
8
  const client = new TriggerXClient(apiKey);
9
9
 
10
10
  // Example: Time-based static job
@@ -18,10 +18,7 @@ async function main() {
18
18
  cronExpression: '0 0 * * *',
19
19
  specificSchedule: '2025-01-01 00:00:00',
20
20
  timezone: 'Asia/Calcutta',
21
- recurring: false,
22
- jobCostPrediction: 0.1,
23
- createdChainId: '11155420',
24
- targetChainId: '11155420',
21
+ chainId: '11155420',
25
22
  targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
26
23
  targetFunction: 'incrementBy',
27
24
  abi: '[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"incrementAmount","type":"uint256"}],"name":"CounterIncremented","type":"event"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"incrementBy","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
@@ -34,7 +31,6 @@ async function main() {
34
31
  // const jobInput: CreateJobInput = {
35
32
  // jobType: JobType.Condition,
36
33
  // argType: ArgType.Static,
37
- // userAddress: '0x7Db951c0E6D8906687B459427eA3F3F2b456473A',
38
34
  // jobTitle: 'SDK Test Condition Job',
39
35
  // timeFrame: 48,
40
36
  // conditionType: 'greaterThan',
@@ -44,9 +40,7 @@ async function main() {
44
40
  // valueSourceUrl: 'https://api.example.com/value',
45
41
  // timezone: 'Asia/Calcutta',
46
42
  // recurring: false,
47
- // jobCostPrediction: 0.1,
48
- // createdChainId: '11155420',
49
- // targetChainId: '11155420',
43
+ // chainId: '11155420',
50
44
  // targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
51
45
  // targetFunction: 'incrementBy',
52
46
  // abi: '[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"incrementAmount","type":"uint256"}],"name":"CounterIncremented","type":"event"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"incrementBy","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
@@ -63,8 +57,8 @@ async function main() {
63
57
  // console.log('Condition Job creation result:', conditionResult);
64
58
 
65
59
  // These would typically come from env/config/user input
66
- const privateKey = '3bd66a68dcde6ede3b38ced6de79489a447e0fac1648b749a5001b0aa167d089';
67
- const providerUrl = 'https://opt-sepolia.g.alchemy.com/v2/m7cIDXzatSUYoiuE1xSY_TnUrK5j9-1W';
60
+ const privateKey = '';
61
+ const providerUrl = '';
68
62
  const provider = new ethers.JsonRpcProvider(providerUrl);
69
63
  const signer = new ethers.Wallet(privateKey, provider);
70
64