sdk-triggerx 0.1.4 → 0.1.6
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/src/api/checkTgBalance.d.ts +4 -1
- package/dist/src/api/checkTgBalance.js +3 -3
- package/dist/src/api/jobs.d.ts +12 -3
- package/dist/src/api/jobs.js +59 -32
- package/dist/src/client.js +1 -1
- package/dist/src/config.js +0 -5
- package/dist/src/types.d.ts +6 -20
- package/dist/test/createJobExample.js +53 -46
- package/package.json +10 -6
- package/src/api/jobs.ts +4 -0
- package/src/config.ts +0 -3
- package/test/createJobExample.ts +15 -13
- package/dist/api/jobs.d.ts +0 -15
- package/dist/api/jobs.js +0 -138
- package/dist/api/tasks.d.ts +0 -4
- package/dist/api/tasks.js +0 -13
- package/dist/client.d.ts +0 -7
- package/dist/client.js +0 -27
- package/dist/config.d.ts +0 -6
- package/dist/config.js +0 -15
- package/dist/contracts/JobRegistry.d.ts +0 -12
- package/dist/contracts/JobRegistry.js +0 -26
- package/dist/contracts/TriggerXContract.d.ts +0 -6
- package/dist/contracts/TriggerXContract.js +0 -14
- package/dist/contracts/abi/JobRegistry.json +0 -1554
- package/dist/contracts/index.d.ts +0 -1
- package/dist/contracts/index.js +0 -17
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -26
- package/dist/src/api/tasks.d.ts +0 -4
- package/dist/src/api/tasks.js +0 -13
- package/dist/types.d.ts +0 -134
- package/dist/types.js +0 -15
- package/dist/utils/errors.d.ts +0 -4
- package/dist/utils/errors.js +0 -17
|
@@ -28,8 +28,8 @@ const checkTgBalance = async (signer) => {
|
|
|
28
28
|
else {
|
|
29
29
|
throw new Error('Unexpected balance format');
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
console.log('tgBalanceEth',
|
|
33
|
-
return
|
|
31
|
+
const tgBalance = ethers_1.ethers.formatEther(tgBalanceWei);
|
|
32
|
+
console.log('tgBalanceEth', tgBalance);
|
|
33
|
+
return { tgBalanceWei, tgBalance };
|
|
34
34
|
};
|
|
35
35
|
exports.checkTgBalance = checkTgBalance;
|
package/dist/src/api/jobs.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { TriggerXClient } from '../client';
|
|
2
2
|
import { TimeBasedJobInput, EventBasedJobInput, ConditionBasedJobInput, CreateJobData, JobResponse } from '../types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
|
-
export declare function toCreateJobDataFromTime(input: TimeBasedJobInput
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare function toCreateJobDataFromTime(input: TimeBasedJobInput, balances: {
|
|
5
|
+
etherBalance: bigint;
|
|
6
|
+
tokenBalanceWei: bigint;
|
|
7
|
+
}, userAddress: string, jobCostPrediction: number): CreateJobData;
|
|
8
|
+
export declare function toCreateJobDataFromEvent(input: EventBasedJobInput, balances: {
|
|
9
|
+
etherBalance: bigint;
|
|
10
|
+
tokenBalanceWei: bigint;
|
|
11
|
+
}, userAddress: string, jobCostPrediction: number): CreateJobData;
|
|
12
|
+
export declare function toCreateJobDataFromCondition(input: ConditionBasedJobInput, balances: {
|
|
13
|
+
etherBalance: bigint;
|
|
14
|
+
tokenBalanceWei: bigint;
|
|
15
|
+
}, userAddress: string, jobCostPrediction: number): CreateJobData;
|
|
7
16
|
export interface CreateJobParams {
|
|
8
17
|
jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput;
|
|
9
18
|
signer: Signer;
|
package/dist/src/api/jobs.js
CHANGED
|
@@ -15,25 +15,25 @@ const checkTgBalance_1 = require("./checkTgBalance");
|
|
|
15
15
|
const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
|
|
16
16
|
const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
|
|
17
17
|
const JOB_REGISTRY_ADDRESS = '0xdB66c11221234C6B19cCBd29868310c31494C21C'; // Set your fixed contract address here
|
|
18
|
-
function toCreateJobDataFromTime(input) {
|
|
18
|
+
function toCreateJobDataFromTime(input, balances, userAddress, jobCostPrediction) {
|
|
19
19
|
return {
|
|
20
20
|
job_id: JOB_ID,
|
|
21
|
-
user_address:
|
|
22
|
-
ether_balance:
|
|
23
|
-
token_balance:
|
|
21
|
+
user_address: userAddress,
|
|
22
|
+
ether_balance: balances.etherBalance,
|
|
23
|
+
token_balance: balances.tokenBalanceWei,
|
|
24
24
|
job_title: input.jobTitle,
|
|
25
25
|
task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
26
26
|
custom: true,
|
|
27
27
|
time_frame: input.timeFrame,
|
|
28
|
-
recurring:
|
|
29
|
-
job_cost_prediction:
|
|
28
|
+
recurring: false,
|
|
29
|
+
job_cost_prediction: jobCostPrediction,
|
|
30
30
|
timezone: input.timezone,
|
|
31
|
-
created_chain_id: input.
|
|
31
|
+
created_chain_id: input.chainId,
|
|
32
32
|
schedule_type: input.scheduleType,
|
|
33
|
-
time_interval: input.timeInterval,
|
|
34
|
-
cron_expression: input.cronExpression,
|
|
35
|
-
specific_schedule: input.specificSchedule,
|
|
36
|
-
target_chain_id: input.
|
|
33
|
+
time_interval: input.scheduleType === 'interval' ? input.timeInterval : undefined,
|
|
34
|
+
cron_expression: input.scheduleType === 'cron' ? input.cronExpression : undefined,
|
|
35
|
+
specific_schedule: input.scheduleType === 'specific' ? input.specificSchedule : undefined,
|
|
36
|
+
target_chain_id: input.chainId,
|
|
37
37
|
target_contract_address: input.targetContractAddress,
|
|
38
38
|
target_function: input.targetFunction,
|
|
39
39
|
abi: input.abi,
|
|
@@ -43,24 +43,24 @@ function toCreateJobDataFromTime(input) {
|
|
|
43
43
|
is_imua: input.isImua ?? true,
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
function toCreateJobDataFromEvent(input) {
|
|
46
|
+
function toCreateJobDataFromEvent(input, balances, userAddress, jobCostPrediction) {
|
|
47
47
|
return {
|
|
48
48
|
job_id: JOB_ID,
|
|
49
|
-
user_address:
|
|
50
|
-
ether_balance:
|
|
51
|
-
token_balance:
|
|
49
|
+
user_address: userAddress,
|
|
50
|
+
ether_balance: balances.etherBalance,
|
|
51
|
+
token_balance: balances.tokenBalanceWei,
|
|
52
52
|
job_title: input.jobTitle,
|
|
53
53
|
task_definition_id: input.dynamicArgumentsScriptUrl ? 4 : 3,
|
|
54
54
|
custom: true,
|
|
55
55
|
time_frame: input.timeFrame,
|
|
56
56
|
recurring: input.recurring ?? false,
|
|
57
|
-
job_cost_prediction:
|
|
57
|
+
job_cost_prediction: jobCostPrediction,
|
|
58
58
|
timezone: input.timezone,
|
|
59
|
-
created_chain_id: input.
|
|
60
|
-
trigger_chain_id: input.triggerChainId,
|
|
59
|
+
created_chain_id: input.chainId,
|
|
60
|
+
trigger_chain_id: input.triggerChainId ?? input.chainId,
|
|
61
61
|
trigger_contract_address: input.triggerContractAddress,
|
|
62
62
|
trigger_event: input.triggerEvent,
|
|
63
|
-
target_chain_id: input.
|
|
63
|
+
target_chain_id: input.chainId,
|
|
64
64
|
target_contract_address: input.targetContractAddress,
|
|
65
65
|
target_function: input.targetFunction,
|
|
66
66
|
abi: input.abi,
|
|
@@ -70,26 +70,26 @@ function toCreateJobDataFromEvent(input) {
|
|
|
70
70
|
is_imua: input.isImua ?? true,
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
function toCreateJobDataFromCondition(input) {
|
|
73
|
+
function toCreateJobDataFromCondition(input, balances, userAddress, jobCostPrediction) {
|
|
74
74
|
return {
|
|
75
75
|
job_id: JOB_ID,
|
|
76
|
-
user_address:
|
|
77
|
-
ether_balance:
|
|
78
|
-
token_balance:
|
|
76
|
+
user_address: userAddress,
|
|
77
|
+
ether_balance: balances.etherBalance,
|
|
78
|
+
token_balance: balances.tokenBalanceWei,
|
|
79
79
|
job_title: input.jobTitle,
|
|
80
80
|
task_definition_id: input.dynamicArgumentsScriptUrl ? 6 : 5,
|
|
81
81
|
custom: true,
|
|
82
82
|
time_frame: input.timeFrame,
|
|
83
83
|
recurring: input.recurring ?? false,
|
|
84
|
-
job_cost_prediction:
|
|
84
|
+
job_cost_prediction: jobCostPrediction,
|
|
85
85
|
timezone: input.timezone,
|
|
86
|
-
created_chain_id: input.
|
|
86
|
+
created_chain_id: input.chainId,
|
|
87
87
|
condition_type: input.conditionType,
|
|
88
88
|
upper_limit: input.upperLimit,
|
|
89
89
|
lower_limit: input.lowerLimit,
|
|
90
90
|
value_source_type: input.valueSourceType,
|
|
91
91
|
value_source_url: input.valueSourceUrl,
|
|
92
|
-
target_chain_id: input.
|
|
92
|
+
target_chain_id: input.chainId,
|
|
93
93
|
target_contract_address: input.targetContractAddress,
|
|
94
94
|
target_function: input.targetFunction,
|
|
95
95
|
abi: input.abi,
|
|
@@ -120,8 +120,12 @@ function encodeJobType4or6Data(recurringJob, ipfsHash) {
|
|
|
120
120
|
*/
|
|
121
121
|
async function createJob(client, params) {
|
|
122
122
|
let { jobInput, signer, encodedData } = params;
|
|
123
|
+
if (!signer) {
|
|
124
|
+
throw new Error('A valid ethers.Signer must be provided to createJob');
|
|
125
|
+
}
|
|
123
126
|
// Use the API key from the client instance
|
|
124
127
|
const apiKey = client.getApiKey();
|
|
128
|
+
const userAddress = await signer.getAddress();
|
|
125
129
|
let jobTitle, timeFrame, targetContractAddress, jobType;
|
|
126
130
|
if ('jobTitle' in jobInput)
|
|
127
131
|
jobTitle = jobInput.jobTitle;
|
|
@@ -129,6 +133,18 @@ async function createJob(client, params) {
|
|
|
129
133
|
timeFrame = jobInput.timeFrame;
|
|
130
134
|
if ('targetContractAddress' in jobInput)
|
|
131
135
|
targetContractAddress = jobInput.targetContractAddress;
|
|
136
|
+
// Validate schedule-specific fields for time-based jobs
|
|
137
|
+
if ('scheduleType' in jobInput) {
|
|
138
|
+
if (jobInput.scheduleType === 'interval' && (jobInput.timeInterval === undefined || jobInput.timeInterval === null)) {
|
|
139
|
+
throw new Error('timeInterval is required when scheduleType is interval');
|
|
140
|
+
}
|
|
141
|
+
if (jobInput.scheduleType === 'cron' && !jobInput.cronExpression) {
|
|
142
|
+
throw new Error('cronExpression is required when scheduleType is cron');
|
|
143
|
+
}
|
|
144
|
+
if (jobInput.scheduleType === 'specific' && !jobInput.specificSchedule) {
|
|
145
|
+
throw new Error('specificSchedule is required when scheduleType is specific');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
132
148
|
// Infer jobType from jobInput
|
|
133
149
|
if ('scheduleType' in jobInput) {
|
|
134
150
|
jobType = jobInput.dynamicArgumentsScriptUrl ? 2 : 1; // Time-based job
|
|
@@ -219,7 +235,7 @@ async function createJob(client, params) {
|
|
|
219
235
|
// We'll throw an error with the fee and let the caller handle the prompt/confirmation.
|
|
220
236
|
// If you want to automate, you can add a `proceed` flag to params in the future.
|
|
221
237
|
// Check if the user has enough TG to cover the job cost prediction
|
|
222
|
-
const tgBalance = await (0, checkTgBalance_1.checkTgBalance)(signer);
|
|
238
|
+
const { tgBalanceWei, tgBalance } = await (0, checkTgBalance_1.checkTgBalance)(signer);
|
|
223
239
|
if (Number(tgBalance) < job_cost_prediction) {
|
|
224
240
|
// Check if user has enabled auto topup
|
|
225
241
|
// For each job type, autotopupTG should be present in jobInput
|
|
@@ -229,9 +245,13 @@ async function createJob(client, params) {
|
|
|
229
245
|
}
|
|
230
246
|
else {
|
|
231
247
|
// autotopupTG is true, automatically top up
|
|
232
|
-
|
|
248
|
+
const requiredTG = Math.ceil(job_cost_prediction * 1000); // 1 TG = 0.001 ETH
|
|
249
|
+
await (0, topupTg_1.topupTg)(requiredTG, signer);
|
|
233
250
|
}
|
|
234
251
|
}
|
|
252
|
+
// Compute balances to store with the job
|
|
253
|
+
const tokenBalanceWei = tgBalanceWei;
|
|
254
|
+
const etherBalance = tokenBalanceWei / 1000n;
|
|
235
255
|
// Patch jobInput with job_cost_prediction for downstream usage
|
|
236
256
|
jobInput.jobCostPrediction = job_cost_prediction;
|
|
237
257
|
const jobId = await (0, JobRegistry_1.createJobOnChain)({
|
|
@@ -246,20 +266,27 @@ async function createJob(client, params) {
|
|
|
246
266
|
});
|
|
247
267
|
// 2. Convert input to CreateJobData
|
|
248
268
|
let jobData;
|
|
269
|
+
const balances = { etherBalance, tokenBalanceWei };
|
|
249
270
|
if ('scheduleType' in jobInput) {
|
|
250
|
-
jobData = toCreateJobDataFromTime(jobInput);
|
|
271
|
+
jobData = toCreateJobDataFromTime(jobInput, balances, userAddress, job_cost_prediction);
|
|
251
272
|
}
|
|
252
273
|
else if ('triggerChainId' in jobInput) {
|
|
253
|
-
jobData = toCreateJobDataFromEvent(jobInput);
|
|
274
|
+
jobData = toCreateJobDataFromEvent(jobInput, balances, userAddress, job_cost_prediction);
|
|
254
275
|
}
|
|
255
276
|
else {
|
|
256
|
-
jobData = toCreateJobDataFromCondition(jobInput);
|
|
277
|
+
jobData = toCreateJobDataFromCondition(jobInput, balances, userAddress, job_cost_prediction);
|
|
257
278
|
}
|
|
258
279
|
// 3. Set the job_id from contract
|
|
259
280
|
jobData.job_id = jobId;
|
|
260
281
|
// 4. Call the API
|
|
261
282
|
try {
|
|
262
|
-
|
|
283
|
+
// Ensure JSON-serializable payload (use numbers for balances)
|
|
284
|
+
const jobDataForApi = {
|
|
285
|
+
...jobData,
|
|
286
|
+
ether_balance: typeof jobData.ether_balance === 'bigint' ? Number(jobData.ether_balance) : Number(jobData.ether_balance),
|
|
287
|
+
token_balance: typeof jobData.token_balance === 'bigint' ? Number(jobData.token_balance) : Number(jobData.token_balance),
|
|
288
|
+
};
|
|
289
|
+
const res = await client.post('/api/jobs', [jobDataForApi], {
|
|
263
290
|
headers: { 'Content-Type': 'application/json', 'X-API-KEY': apiKey },
|
|
264
291
|
});
|
|
265
292
|
return { success: true, data: res };
|
package/dist/src/client.js
CHANGED
|
@@ -11,7 +11,7 @@ class TriggerXClient {
|
|
|
11
11
|
this.apiKey = apiKey; // Initialize the apiKey
|
|
12
12
|
const baseConfig = (0, config_1.getConfig)();
|
|
13
13
|
this.client = axios_1.default.create({
|
|
14
|
-
baseURL: config?.baseURL || baseConfig.apiUrl || 'http://localhost:9002
|
|
14
|
+
baseURL: config?.baseURL || baseConfig.apiUrl || 'https://data.triggerx.network', //http://localhost:9002 , https://data.triggerx.network
|
|
15
15
|
headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
|
|
16
16
|
...config,
|
|
17
17
|
});
|
package/dist/src/config.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getConfig = getConfig;
|
|
7
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
dotenv_1.default.config();
|
|
9
4
|
function getConfig() {
|
|
10
5
|
return {
|
|
11
6
|
apiKey: process.env.API_KEY || '',
|
package/dist/src/types.d.ts
CHANGED
|
@@ -28,9 +28,6 @@ export type CreateJobInput = (TimeBasedJobInput & {
|
|
|
28
28
|
argType: ArgType.Static | ArgType.Dynamic;
|
|
29
29
|
});
|
|
30
30
|
export interface TimeBasedJobInput {
|
|
31
|
-
userAddress: string;
|
|
32
|
-
etherBalance: BigInt | number;
|
|
33
|
-
tokenBalance: BigInt | number;
|
|
34
31
|
jobTitle: string;
|
|
35
32
|
timeFrame: number;
|
|
36
33
|
scheduleType: 'cron' | 'specific' | 'interval';
|
|
@@ -38,10 +35,7 @@ export interface TimeBasedJobInput {
|
|
|
38
35
|
cronExpression?: string;
|
|
39
36
|
specificSchedule?: string;
|
|
40
37
|
timezone: string;
|
|
41
|
-
|
|
42
|
-
jobCostPrediction: number;
|
|
43
|
-
createdChainId: string;
|
|
44
|
-
targetChainId: string;
|
|
38
|
+
chainId: string;
|
|
45
39
|
targetContractAddress: string;
|
|
46
40
|
targetFunction: string;
|
|
47
41
|
abi: string;
|
|
@@ -51,9 +45,6 @@ export interface TimeBasedJobInput {
|
|
|
51
45
|
autotopupTG?: boolean;
|
|
52
46
|
}
|
|
53
47
|
export interface EventBasedJobInput {
|
|
54
|
-
userAddress: string;
|
|
55
|
-
etherBalance: BigInt | number;
|
|
56
|
-
tokenBalance: BigInt | number;
|
|
57
48
|
jobTitle: string;
|
|
58
49
|
timeFrame: number;
|
|
59
50
|
triggerChainId: string;
|
|
@@ -61,9 +52,7 @@ export interface EventBasedJobInput {
|
|
|
61
52
|
triggerEvent: string;
|
|
62
53
|
timezone: string;
|
|
63
54
|
recurring?: boolean;
|
|
64
|
-
|
|
65
|
-
createdChainId: string;
|
|
66
|
-
targetChainId: string;
|
|
55
|
+
chainId: string;
|
|
67
56
|
targetContractAddress: string;
|
|
68
57
|
targetFunction: string;
|
|
69
58
|
abi: string;
|
|
@@ -73,21 +62,16 @@ export interface EventBasedJobInput {
|
|
|
73
62
|
autotopupTG?: boolean;
|
|
74
63
|
}
|
|
75
64
|
export interface ConditionBasedJobInput {
|
|
76
|
-
userAddress: string;
|
|
77
|
-
etherBalance: BigInt | number;
|
|
78
|
-
tokenBalance: BigInt | number;
|
|
79
65
|
jobTitle: string;
|
|
80
66
|
timeFrame: number;
|
|
81
|
-
conditionType:
|
|
67
|
+
conditionType: 'greater_than' | 'less_than' | 'between' | 'equals' | 'not_equals' | 'greater_equal' | 'less_equal';
|
|
82
68
|
upperLimit: number;
|
|
83
69
|
lowerLimit: number;
|
|
84
70
|
valueSourceType: string;
|
|
85
71
|
valueSourceUrl: string;
|
|
86
72
|
timezone: string;
|
|
87
73
|
recurring?: boolean;
|
|
88
|
-
|
|
89
|
-
createdChainId: string;
|
|
90
|
-
targetChainId: string;
|
|
74
|
+
chainId: string;
|
|
91
75
|
targetContractAddress: string;
|
|
92
76
|
targetFunction: string;
|
|
93
77
|
abi: string;
|
|
@@ -188,6 +172,7 @@ export interface EventJobData {
|
|
|
188
172
|
trigger_chain_id: string;
|
|
189
173
|
trigger_contract_address: string;
|
|
190
174
|
trigger_event: string;
|
|
175
|
+
timezone: string;
|
|
191
176
|
target_chain_id: string;
|
|
192
177
|
target_contract_address: string;
|
|
193
178
|
target_function: string;
|
|
@@ -210,6 +195,7 @@ export interface ConditionJobData {
|
|
|
210
195
|
lower_limit: number;
|
|
211
196
|
value_source_type: string;
|
|
212
197
|
value_source_url: string;
|
|
198
|
+
timezone: string;
|
|
213
199
|
target_chain_id: string;
|
|
214
200
|
target_contract_address: string;
|
|
215
201
|
target_function: string;
|
|
@@ -4,59 +4,64 @@ const src_1 = require("../src");
|
|
|
4
4
|
const types_1 = require("../src/types");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
async function main() {
|
|
7
|
-
const apiKey = 'TGRX-
|
|
7
|
+
const apiKey = 'TGRX-02c20872-4bdf-4fd9-9e74-556861b16690';
|
|
8
8
|
const client = new src_1.TriggerXClient(apiKey);
|
|
9
|
-
//
|
|
9
|
+
// Example: Time-based static job
|
|
10
|
+
const jobInput = {
|
|
11
|
+
jobType: types_1.JobType.Time,
|
|
12
|
+
argType: types_1.ArgType.Static,
|
|
13
|
+
jobTitle: 'SDK Test Time Job for mainnet',
|
|
14
|
+
timeFrame: 36,
|
|
15
|
+
scheduleType: 'interval',
|
|
16
|
+
timeInterval: 33,
|
|
17
|
+
cronExpression: '0 0 * * *',
|
|
18
|
+
specificSchedule: '2025-01-01 00:00:00',
|
|
19
|
+
timezone: 'Asia/Calcutta',
|
|
20
|
+
chainId: '421614',
|
|
21
|
+
targetContractAddress: '0xDE85FE97A73B891f12CbBF1210cc225AF332C90B',
|
|
22
|
+
targetFunction: 'helloWorld',
|
|
23
|
+
abi: '[{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cnt","type":"uint256"}],"name":"helloWorld","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
|
|
24
|
+
isImua: false,
|
|
25
|
+
arguments: ['3'],
|
|
26
|
+
dynamicArgumentsScriptUrl: '',
|
|
27
|
+
autotopupTG: true,
|
|
28
|
+
};
|
|
29
|
+
// // Example: Condition-based static job
|
|
10
30
|
// const jobInput: CreateJobInput = {
|
|
11
|
-
// jobType: JobType.
|
|
31
|
+
// jobType: JobType.Condition,
|
|
12
32
|
// argType: ArgType.Static,
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// cronExpression: '0 0 * * *',
|
|
21
|
-
// specificSchedule: '2025-01-01 00:00:00',
|
|
33
|
+
// jobTitle: 'SDK Test Condition Job',
|
|
34
|
+
// timeFrame: 48,
|
|
35
|
+
// conditionType: 'greaterThan',
|
|
36
|
+
// upperLimit: 100,
|
|
37
|
+
// lowerLimit: 10,
|
|
38
|
+
// valueSourceType: 'http',
|
|
39
|
+
// valueSourceUrl: 'https://api.example.com/value',
|
|
22
40
|
// timezone: 'Asia/Calcutta',
|
|
23
41
|
// recurring: false,
|
|
24
|
-
//
|
|
25
|
-
// createdChainId: '11155420',
|
|
26
|
-
// targetChainId: '11155420',
|
|
42
|
+
// chainId: '11155420',
|
|
27
43
|
// targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
|
|
28
44
|
// targetFunction: 'incrementBy',
|
|
29
45
|
// 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"}]',
|
|
30
46
|
// isImua: true,
|
|
31
|
-
// arguments: ['
|
|
47
|
+
// arguments: ['5'],
|
|
32
48
|
// dynamicArgumentsScriptUrl: '',
|
|
33
49
|
// };
|
|
34
|
-
// Example:
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
recurring: false,
|
|
50
|
-
jobCostPrediction: 0.1,
|
|
51
|
-
createdChainId: '11155420',
|
|
52
|
-
targetChainId: '11155420',
|
|
53
|
-
targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
|
|
54
|
-
targetFunction: 'incrementBy',
|
|
55
|
-
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"}]',
|
|
56
|
-
isImua: true,
|
|
57
|
-
arguments: ['5'],
|
|
58
|
-
dynamicArgumentsScriptUrl: '',
|
|
59
|
-
};
|
|
50
|
+
// // Example: Event-based static job
|
|
51
|
+
// const eventJobInput: CreateJobInput = {
|
|
52
|
+
// jobType: JobType.Event,
|
|
53
|
+
// argType: ArgType.Static,
|
|
54
|
+
// jobTitle: 'SDK Test Event Job',
|
|
55
|
+
// timeFrame: 25,
|
|
56
|
+
// triggerChainId: '11155420',
|
|
57
|
+
// triggerContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
|
|
58
|
+
// triggerEvent: 'CounterIncremented(uint256,uint256,uint256)',
|
|
59
|
+
// timezone: 'Asia/Calcutta',
|
|
60
|
+
// chainId: '11155420',
|
|
61
|
+
// targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
|
|
62
|
+
// targetFunction: 'incrementBy',
|
|
63
|
+
// 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"}]',
|
|
64
|
+
// };
|
|
60
65
|
// To test, you can call createJob with this input as well:
|
|
61
66
|
// const conditionResult = await createJob(client, {
|
|
62
67
|
// jobInput: conditionJobInput,
|
|
@@ -64,13 +69,15 @@ async function main() {
|
|
|
64
69
|
// });
|
|
65
70
|
// console.log('Condition Job creation result:', conditionResult);
|
|
66
71
|
// These would typically come from env/config/user input
|
|
67
|
-
const privateKey = '';
|
|
68
|
-
const providerUrl = 'https://
|
|
72
|
+
const privateKey = '0x3bd66a68dcde6ede3b38ced6de79489a447e0fac1648b749a5001b0aa167d089';
|
|
73
|
+
const providerUrl = 'https://arb-sepolia.g.alchemy.com/v2/zU9y7U094z69CQwzpro2mCKnW3A8gtlx';
|
|
69
74
|
const provider = new ethers_1.ethers.JsonRpcProvider(providerUrl);
|
|
70
75
|
const signer = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
76
|
+
console.log('Job input:', client);
|
|
71
77
|
const result = await (0, src_1.createJob)(client, {
|
|
72
|
-
jobInput,
|
|
73
|
-
|
|
78
|
+
jobInput: jobInput,
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
signer: signer,
|
|
74
81
|
});
|
|
75
82
|
console.log('Job creation result:', result);
|
|
76
83
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdk-triggerx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"test": "jest",
|
|
10
|
-
"lint": "eslint src --ext .ts"
|
|
10
|
+
"lint": "eslint src --ext .ts",
|
|
11
|
+
"example": "npm run -s build && node dist/test/createJobExample.js"
|
|
11
12
|
},
|
|
12
13
|
"author": "",
|
|
13
14
|
"license": "MIT",
|
|
@@ -16,17 +17,20 @@
|
|
|
16
17
|
},
|
|
17
18
|
"keywords": [],
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"axios": "^1.11.0"
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
"axios": "^1.11.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"ethers": ">=6 <7"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@types/jest": "^30.0.0",
|
|
25
27
|
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
26
28
|
"@typescript-eslint/parser": "^8.38.0",
|
|
27
29
|
"eslint": "^9.32.0",
|
|
30
|
+
"ethers": "^6.15.0",
|
|
28
31
|
"jest": "^30.0.5",
|
|
29
32
|
"ts-jest": "^29.4.0",
|
|
30
33
|
"typescript": "^5.8.3"
|
|
31
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false
|
|
32
36
|
}
|
package/src/api/jobs.ts
CHANGED
|
@@ -164,6 +164,10 @@ export async function createJob(
|
|
|
164
164
|
): Promise<JobResponse> {
|
|
165
165
|
let { jobInput, signer, encodedData } = params;
|
|
166
166
|
|
|
167
|
+
if (!signer) {
|
|
168
|
+
throw new Error('A valid ethers.Signer must be provided to createJob');
|
|
169
|
+
}
|
|
170
|
+
|
|
167
171
|
// Use the API key from the client instance
|
|
168
172
|
const apiKey = client.getApiKey();
|
|
169
173
|
|
package/src/config.ts
CHANGED
package/test/createJobExample.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { ethers } from 'ethers';
|
|
|
4
4
|
|
|
5
5
|
async function main() {
|
|
6
6
|
|
|
7
|
-
const apiKey = '';
|
|
8
|
-
const client = new TriggerXClient(apiKey);
|
|
7
|
+
const apiKey = 'TGRX-02c20872-4bdf-4fd9-9e74-556861b16690';
|
|
8
|
+
const client = new TriggerXClient(apiKey as any);
|
|
9
9
|
|
|
10
10
|
// Example: Time-based static job
|
|
11
11
|
const jobInput: CreateJobInput = {
|
|
@@ -18,13 +18,14 @@ async function main() {
|
|
|
18
18
|
cronExpression: '0 0 * * *',
|
|
19
19
|
specificSchedule: '2025-01-01 00:00:00',
|
|
20
20
|
timezone: 'Asia/Calcutta',
|
|
21
|
-
chainId: '
|
|
22
|
-
targetContractAddress: '
|
|
23
|
-
targetFunction: '
|
|
24
|
-
abi:
|
|
25
|
-
isImua:
|
|
21
|
+
chainId: '421614',
|
|
22
|
+
targetContractAddress: '0xDE85FE97A73B891f12CbBF1210cc225AF332C90B',
|
|
23
|
+
targetFunction: 'helloWorld',
|
|
24
|
+
abi:'[{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cnt","type":"uint256"}],"name":"helloWorld","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
|
|
25
|
+
isImua: false,
|
|
26
26
|
arguments: ['3'],
|
|
27
27
|
dynamicArgumentsScriptUrl: '',
|
|
28
|
+
autotopupTG: true,
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
// // Example: Condition-based static job
|
|
@@ -73,17 +74,18 @@ async function main() {
|
|
|
73
74
|
// console.log('Condition Job creation result:', conditionResult);
|
|
74
75
|
|
|
75
76
|
// These would typically come from env/config/user input
|
|
76
|
-
const privateKey = '';
|
|
77
|
-
const providerUrl = '';
|
|
77
|
+
const privateKey = '0x3bd66a68dcde6ede3b38ced6de79489a447e0fac1648b749a5001b0aa167d089';
|
|
78
|
+
const providerUrl = 'https://arb-sepolia.g.alchemy.com/v2/zU9y7U094z69CQwzpro2mCKnW3A8gtlx';
|
|
78
79
|
const provider = new ethers.JsonRpcProvider(providerUrl);
|
|
79
80
|
const signer = new ethers.Wallet(privateKey, provider);
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
console.log('Job input:', client);
|
|
82
83
|
const result = await createJob(client, {
|
|
83
|
-
jobInput,
|
|
84
|
-
|
|
84
|
+
jobInput: jobInput as any,
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
signer: signer as any,
|
|
85
87
|
});
|
|
86
88
|
console.log('Job creation result:', result);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
main().catch(console.error);
|
|
91
|
+
main().catch(console.error);
|
package/dist/api/jobs.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TriggerXClient } from '../client';
|
|
2
|
-
import { TimeBasedJobInput, EventBasedJobInput, ConditionBasedJobInput, CreateJobData, JobResponse } from '../types';
|
|
3
|
-
export declare function toCreateJobDataFromTime(input: TimeBasedJobInput): CreateJobData;
|
|
4
|
-
export declare function toCreateJobDataFromEvent(input: EventBasedJobInput): CreateJobData;
|
|
5
|
-
export declare function toCreateJobDataFromCondition(input: ConditionBasedJobInput): CreateJobData;
|
|
6
|
-
export interface CreateJobParams {
|
|
7
|
-
jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput;
|
|
8
|
-
privateKey: string;
|
|
9
|
-
providerUrl: string;
|
|
10
|
-
contractAddress: string;
|
|
11
|
-
abi: any;
|
|
12
|
-
encodedData: string;
|
|
13
|
-
jobType: number;
|
|
14
|
-
}
|
|
15
|
-
export declare function createJob(client: TriggerXClient, params: CreateJobParams): Promise<JobResponse>;
|