sdk-triggerx 0.1.2 → 0.1.4

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
@@ -50,6 +50,16 @@ const client = new TriggerXClient('YOUR_API_KEY');
50
50
  - `ArgType.Static`: Hardcoded values
51
51
  - `ArgType.Dynamic`: Runtime values fetched from a script
52
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
+
53
63
  ---
54
64
 
55
65
  #### 🕒 Example: Time-based Static Job
@@ -58,27 +68,26 @@ const client = new TriggerXClient('YOUR_API_KEY');
58
68
  import { createJob, JobType, ArgType } from 'sdk-triggerx';
59
69
 
60
70
  const jobInput = {
61
- jobType: JobType.Time,
62
- argType: ArgType.Static,
63
- jobTitle: 'My Time Job',
64
- timeFrame: 36,
65
- scheduleType: 'interval',
66
- timeInterval: 33,
67
- cronExpression: '0 0 * * *',
68
- specificSchedule: '2025-01-01 00:00:00',
69
- timezone: 'Asia/Calcutta',
70
- recurring: false,
71
- jobCostPrediction: 0.1,
72
- createdChainId: '11155420',
73
- targetChainId: '11155420',
74
- targetContractAddress: '0x...',
75
- targetFunction: 'incrementBy',
76
- abi: '[...]',
77
- isImua: true,
78
- arguments: ['3'],
79
- dynamicArgumentsScriptUrl: '',
80
- // if more TG needed auto top-up TG must true for automatially top up TG
81
- 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
82
91
  };
83
92
 
84
93
  const signer = /* ethers.Signer instance */;
@@ -92,25 +101,27 @@ console.log(result);
92
101
 
93
102
  ```ts
94
103
  const jobInput = {
95
- jobType: JobType.Event,
96
- argType: ArgType.Dynamic,
97
- jobTitle: 'My Event Job',
98
- timeFrame: 36,
99
- recurring: true,
100
- jobCostPrediction: 0.2,
101
- timezone: 'Asia/Calcutta',
102
- createdChainId: '11155420',
103
- triggerChainId: '11155420',
104
- triggerContractAddress: '0x...',
105
- triggerEvent: 'CounterIncremented',
106
- targetChainId: '11155420',
107
- targetContractAddress: '0x...',
108
- targetFunction: 'incrementBy',
109
- abi: '[...]',
110
- arguments: [],
111
- dynamicArgumentsScriptUrl: 'https://your-ipfs-url',
112
- isImua: true,
113
- 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
114
125
  };
115
126
 
116
127
  const result = await createJob(client, { jobInput, signer });
@@ -123,27 +134,29 @@ console.log(result);
123
134
 
124
135
  ```ts
125
136
  const jobInput = {
126
- jobType: JobType.Condition,
127
- argType: ArgType.Static,
128
- jobTitle: 'My Condition Job',
129
- timeFrame: 36,
130
- recurring: false,
131
- jobCostPrediction: 0.3,
132
- timezone: 'Asia/Calcutta',
133
- createdChainId: '11155420',
134
- conditionType: 'greaterThan',
135
- upperLimit: 100,
136
- lowerLimit: 10,
137
- valueSourceType: 'api',
138
- valueSourceUrl: 'https://api.example.com/value',
139
- targetChainId: '11155420',
140
- targetContractAddress: '0x...',
141
- targetFunction: 'incrementBy',
142
- abi: '[...]',
143
- arguments: ['5'],
144
- dynamicArgumentsScriptUrl: '',
145
- isImua: true,
146
- 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
147
160
  };
148
161
 
149
162
  const result = await createJob(client, { jobInput, signer });
@@ -215,22 +228,6 @@ Includes:
215
228
 
216
229
  ---
217
230
 
218
- ## 🗂️ Project Structure
219
-
220
- ```
221
- sdk-triggerx/
222
- ├── index.ts # Entry point
223
- ├── client.ts # Axios client wrapper
224
- ├── config.ts # Config and environment loader
225
- ├── types.ts # Shared interfaces and enums
226
- ├── api/ # Backend API modules
227
- ├── contracts/ # Contract logic and ABIs
228
- ├── utils/ # Error and helper utilities
229
- ├── test/ # Unit/integration tests
230
- └── scripts/ # Example/test scripts
231
- ```
232
-
233
- ---
234
231
 
235
232
  ## ✅ Requirements
236
233
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdk-triggerx",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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/client.ts CHANGED
@@ -9,7 +9,7 @@ export class TriggerXClient {
9
9
  this.apiKey = apiKey; // Initialize the apiKey
10
10
  const baseConfig = getConfig();
11
11
  this.client = axios.create({
12
- baseURL: config?.baseURL || baseConfig.apiUrl || 'http://localhost:9002', //http://localhost:9002 , https://data.triggerx.network
12
+ baseURL: config?.baseURL || baseConfig.apiUrl || 'https://data.triggerx.network', //http://localhost:9002 , https://data.triggerx.network
13
13
  headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
14
14
  ...config,
15
15
  });
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;
@@ -11,17 +11,14 @@ async function main() {
11
11
  const jobInput: CreateJobInput = {
12
12
  jobType: JobType.Time,
13
13
  argType: ArgType.Static,
14
- jobTitle: 'SDK Test Time Job',
14
+ jobTitle: 'SDK Test Time Job for mainnet',
15
15
  timeFrame: 36,
16
16
  scheduleType: 'interval',
17
17
  timeInterval: 33,
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"}]',
@@ -43,9 +40,7 @@ async function main() {
43
40
  // valueSourceUrl: 'https://api.example.com/value',
44
41
  // timezone: 'Asia/Calcutta',
45
42
  // recurring: false,
46
- // jobCostPrediction: 0.1,
47
- // createdChainId: '11155420',
48
- // targetChainId: '11155420',
43
+ // chainId: '11155420',
49
44
  // targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
50
45
  // targetFunction: 'incrementBy',
51
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"}]',
@@ -54,6 +49,22 @@ async function main() {
54
49
  // dynamicArgumentsScriptUrl: '',
55
50
  // };
56
51
 
52
+ // // Example: Event-based static job
53
+ // const eventJobInput: CreateJobInput = {
54
+ // jobType: JobType.Event,
55
+ // argType: ArgType.Static,
56
+ // jobTitle: 'SDK Test Event Job',
57
+ // timeFrame: 25,
58
+ // triggerChainId: '11155420',
59
+ // triggerContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
60
+ // triggerEvent: 'CounterIncremented(uint256,uint256,uint256)',
61
+ // timezone: 'Asia/Calcutta',
62
+ // chainId: '11155420',
63
+ // targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
64
+ // targetFunction: 'incrementBy',
65
+ // 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"}]',
66
+ // };
67
+
57
68
  // To test, you can call createJob with this input as well:
58
69
  // const conditionResult = await createJob(client, {
59
70
  // jobInput: conditionJobInput,