sdk-triggerx 0.1.5 → 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.
- package/dist/api/jobs.d.ts +21 -9
- package/dist/api/jobs.js +195 -39
- package/dist/client.d.ts +4 -1
- package/dist/client.js +13 -3
- package/dist/contracts/JobRegistry.d.ts +3 -3
- package/dist/contracts/JobRegistry.js +2 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/types.d.ts +118 -20
- package/package.json +14 -10
- package/.eslintrc.json +0 -16
- package/dist/api/tasks.d.ts +0 -4
- package/dist/api/tasks.js +0 -13
- package/dist/src/api/jobs.d.ts +0 -27
- package/dist/src/api/jobs.js +0 -297
- package/dist/src/api/tasks.d.ts +0 -4
- package/dist/src/api/tasks.js +0 -13
- package/dist/src/client.d.ts +0 -10
- package/dist/src/client.js +0 -37
- package/dist/src/config.d.ts +0 -6
- package/dist/src/config.js +0 -10
- package/dist/src/contracts/JobRegistry.d.ts +0 -12
- package/dist/src/contracts/JobRegistry.js +0 -24
- package/dist/src/contracts/TriggerXContract.d.ts +0 -6
- package/dist/src/contracts/TriggerXContract.js +0 -14
- package/dist/src/contracts/abi/JobRegistry.json +0 -1554
- package/dist/src/contracts/index.d.ts +0 -1
- package/dist/src/contracts/index.js +0 -17
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.js +0 -25
- package/dist/src/types.d.ts +0 -232
- package/dist/src/types.js +0 -15
- package/dist/src/utils/errors.d.ts +0 -4
- package/dist/src/utils/errors.js +0 -17
- package/dist/test/createJobExample.d.ts +0 -1
- package/dist/test/createJobExample.js +0 -84
- package/dist/test/deleteJob.test.d.ts +0 -1
- package/dist/test/deleteJob.test.js +0 -22
- package/dist/test/example.test.d.ts +0 -1
- package/dist/test/example.test.js +0 -11
- package/dist/test/getJobDataById.test.d.ts +0 -1
- package/dist/test/getJobDataById.test.js +0 -23
- package/dist/test/getUserData.test.d.ts +0 -1
- package/dist/test/getUserData.test.js +0 -22
- package/dist/test/getjob.test.d.ts +0 -1
- package/dist/test/getjob.test.js +0 -21
- package/dist/test/testTgFunctions.d.ts +0 -1
- package/dist/test/testTgFunctions.js +0 -56
- package/jest.config.js +0 -7
- package/scripts/deploy.ts +0 -9
- package/src/api/checkTgBalance.ts +0 -27
- package/src/api/deleteJob.ts +0 -22
- package/src/api/getJobDataById.ts +0 -24
- package/src/api/getUserData.ts +0 -24
- package/src/api/getjob.ts +0 -26
- package/src/api/jobs.ts +0 -352
- package/src/api/topupTg.ts +0 -17
- package/src/api/withdrawTg.ts +0 -25
- package/src/client.ts +0 -38
- package/src/config.ts +0 -13
- package/src/contracts/JobRegistry.ts +0 -45
- package/src/contracts/TriggerXContract.ts +0 -14
- package/src/contracts/abi/.gitkeep +0 -1
- package/src/contracts/abi/GasRegistry.json +0 -607
- package/src/contracts/abi/JobRegistry.json +0 -1554
- package/src/contracts/index.ts +0 -1
- package/src/index.ts +0 -7
- package/src/types.ts +0 -249
- package/src/utils/errors.ts +0 -13
- package/test/createJobExample.ts +0 -91
- package/test/deleteJob.test.ts +0 -25
- package/test/example.test.d.ts +0 -1
- package/test/example.test.js +0 -11
- package/test/example.test.ts +0 -10
- package/test/getJobDataById.test.ts +0 -27
- package/test/getUserData.test.ts +0 -25
- package/test/getjob.test.ts +0 -23
- package/test/testTgFunctions.ts +0 -56
- package/tsconfig.json +0 -16
- /package/dist/{src/api → api}/checkTgBalance.d.ts +0 -0
- /package/dist/{src/api → api}/checkTgBalance.js +0 -0
- /package/dist/{src/api → api}/deleteJob.d.ts +0 -0
- /package/dist/{src/api → api}/deleteJob.js +0 -0
- /package/dist/{src/api → api}/getJobDataById.d.ts +0 -0
- /package/dist/{src/api → api}/getJobDataById.js +0 -0
- /package/dist/{src/api → api}/getUserData.d.ts +0 -0
- /package/dist/{src/api → api}/getUserData.js +0 -0
- /package/dist/{src/api → api}/getjob.d.ts +0 -0
- /package/dist/{src/api → api}/getjob.js +0 -0
- /package/dist/{src/api → api}/topupTg.d.ts +0 -0
- /package/dist/{src/api → api}/topupTg.js +0 -0
- /package/dist/{src/api → api}/withdrawTg.d.ts +0 -0
- /package/dist/{src/api → api}/withdrawTg.js +0 -0
- /package/dist/{src/contracts → contracts}/abi/GasRegistry.json +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdk-triggerx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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",
|
|
@@ -9,27 +9,31 @@
|
|
|
9
9
|
"test": "jest",
|
|
10
10
|
"lint": "eslint src --ext .ts"
|
|
11
11
|
},
|
|
12
|
-
"author": "",
|
|
12
|
+
"author": "Nipun Shah",
|
|
13
13
|
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/trigg3rX/triggerx-newSDK.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": ["triggerx", "sdk", "web3", "blockchain", "ethers"],
|
|
14
19
|
"directories": {
|
|
15
20
|
"test": "test"
|
|
16
21
|
},
|
|
17
|
-
"
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
18
25
|
"dependencies": {
|
|
19
|
-
"axios": "^1.11.0"
|
|
20
|
-
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"ethers": ">=6 <7"
|
|
26
|
+
"axios": "^1.11.0",
|
|
27
|
+
"ethers": "^6.15.0"
|
|
23
28
|
},
|
|
24
29
|
"devDependencies": {
|
|
25
|
-
"ethers": "^6.15.0",
|
|
26
30
|
"@types/jest": "^30.0.0",
|
|
27
31
|
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
28
32
|
"@typescript-eslint/parser": "^8.38.0",
|
|
33
|
+
"dotenv": "^17.2.1",
|
|
29
34
|
"eslint": "^9.32.0",
|
|
30
35
|
"jest": "^30.0.5",
|
|
31
36
|
"ts-jest": "^29.4.0",
|
|
32
37
|
"typescript": "^5.8.3"
|
|
33
|
-
}
|
|
34
|
-
"sideEffects": false
|
|
38
|
+
}
|
|
35
39
|
}
|
package/.eslintrc.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parser": "@typescript-eslint/parser",
|
|
3
|
-
"extends": [
|
|
4
|
-
"plugin:@typescript-eslint/recommended"
|
|
5
|
-
],
|
|
6
|
-
"env": {
|
|
7
|
-
"node": true,
|
|
8
|
-
"es2020": true,
|
|
9
|
-
"jest": true
|
|
10
|
-
},
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaVersion": 2020,
|
|
13
|
-
"sourceType": "module"
|
|
14
|
-
},
|
|
15
|
-
"rules": {}
|
|
16
|
-
}
|
package/dist/api/tasks.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { TriggerXClient } from '../client';
|
|
2
|
-
import { Task, ApiResponse } from '../types';
|
|
3
|
-
export declare function getTasks(client: TriggerXClient): Promise<ApiResponse<Task[]>>;
|
|
4
|
-
export declare function createTask(client: TriggerXClient, task: Partial<Task>): Promise<ApiResponse<Task>>;
|
package/dist/api/tasks.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTasks = getTasks;
|
|
4
|
-
exports.createTask = createTask;
|
|
5
|
-
async function getTasks(client) {
|
|
6
|
-
// Placeholder implementation
|
|
7
|
-
return client.get('/tasks');
|
|
8
|
-
}
|
|
9
|
-
async function createTask(client, task) {
|
|
10
|
-
// Placeholder implementation
|
|
11
|
-
// return client.post<ApiResponse<Task>>('/tasks', task);
|
|
12
|
-
return { data: { id: '1', name: task.name || '', status: 'pending', createdAt: new Date().toISOString() } };
|
|
13
|
-
}
|
package/dist/src/api/jobs.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { TriggerXClient } from '../client';
|
|
2
|
-
import { TimeBasedJobInput, EventBasedJobInput, ConditionBasedJobInput, CreateJobData, JobResponse } from '../types';
|
|
3
|
-
import { Signer } from 'ethers';
|
|
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;
|
|
16
|
-
export interface CreateJobParams {
|
|
17
|
-
jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput;
|
|
18
|
-
signer: Signer;
|
|
19
|
-
encodedData?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Create a job on the blockchain.
|
|
23
|
-
* @param client TriggerXClient instance
|
|
24
|
-
* @param params Parameters for creating the job
|
|
25
|
-
* @returns JobResponse containing the result of the job creation
|
|
26
|
-
*/
|
|
27
|
-
export declare function createJob(client: TriggerXClient, params: CreateJobParams): Promise<JobResponse>;
|
package/dist/src/api/jobs.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.toCreateJobDataFromTime = toCreateJobDataFromTime;
|
|
7
|
-
exports.toCreateJobDataFromEvent = toCreateJobDataFromEvent;
|
|
8
|
-
exports.toCreateJobDataFromCondition = toCreateJobDataFromCondition;
|
|
9
|
-
exports.createJob = createJob;
|
|
10
|
-
const JobRegistry_1 = require("../contracts/JobRegistry");
|
|
11
|
-
const ethers_1 = require("ethers");
|
|
12
|
-
const JobRegistry_json_1 = __importDefault(require("../contracts/abi/JobRegistry.json"));
|
|
13
|
-
const topupTg_1 = require("./topupTg");
|
|
14
|
-
const checkTgBalance_1 = require("./checkTgBalance");
|
|
15
|
-
const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
|
|
16
|
-
const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
|
|
17
|
-
const JOB_REGISTRY_ADDRESS = '0xdB66c11221234C6B19cCBd29868310c31494C21C'; // Set your fixed contract address here
|
|
18
|
-
function toCreateJobDataFromTime(input, balances, userAddress, jobCostPrediction) {
|
|
19
|
-
return {
|
|
20
|
-
job_id: JOB_ID,
|
|
21
|
-
user_address: userAddress,
|
|
22
|
-
ether_balance: balances.etherBalance,
|
|
23
|
-
token_balance: balances.tokenBalanceWei,
|
|
24
|
-
job_title: input.jobTitle,
|
|
25
|
-
task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
26
|
-
custom: true,
|
|
27
|
-
time_frame: input.timeFrame,
|
|
28
|
-
recurring: false,
|
|
29
|
-
job_cost_prediction: jobCostPrediction,
|
|
30
|
-
timezone: input.timezone,
|
|
31
|
-
created_chain_id: input.chainId,
|
|
32
|
-
schedule_type: input.scheduleType,
|
|
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
|
-
target_contract_address: input.targetContractAddress,
|
|
38
|
-
target_function: input.targetFunction,
|
|
39
|
-
abi: input.abi,
|
|
40
|
-
arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
41
|
-
arguments: input.arguments,
|
|
42
|
-
dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
|
|
43
|
-
is_imua: input.isImua ?? true,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function toCreateJobDataFromEvent(input, balances, userAddress, jobCostPrediction) {
|
|
47
|
-
return {
|
|
48
|
-
job_id: JOB_ID,
|
|
49
|
-
user_address: userAddress,
|
|
50
|
-
ether_balance: balances.etherBalance,
|
|
51
|
-
token_balance: balances.tokenBalanceWei,
|
|
52
|
-
job_title: input.jobTitle,
|
|
53
|
-
task_definition_id: input.dynamicArgumentsScriptUrl ? 4 : 3,
|
|
54
|
-
custom: true,
|
|
55
|
-
time_frame: input.timeFrame,
|
|
56
|
-
recurring: input.recurring ?? false,
|
|
57
|
-
job_cost_prediction: jobCostPrediction,
|
|
58
|
-
timezone: input.timezone,
|
|
59
|
-
created_chain_id: input.chainId,
|
|
60
|
-
trigger_chain_id: input.triggerChainId ?? input.chainId,
|
|
61
|
-
trigger_contract_address: input.triggerContractAddress,
|
|
62
|
-
trigger_event: input.triggerEvent,
|
|
63
|
-
target_chain_id: input.chainId,
|
|
64
|
-
target_contract_address: input.targetContractAddress,
|
|
65
|
-
target_function: input.targetFunction,
|
|
66
|
-
abi: input.abi,
|
|
67
|
-
arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
68
|
-
arguments: input.arguments,
|
|
69
|
-
dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
|
|
70
|
-
is_imua: input.isImua ?? true,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function toCreateJobDataFromCondition(input, balances, userAddress, jobCostPrediction) {
|
|
74
|
-
return {
|
|
75
|
-
job_id: JOB_ID,
|
|
76
|
-
user_address: userAddress,
|
|
77
|
-
ether_balance: balances.etherBalance,
|
|
78
|
-
token_balance: balances.tokenBalanceWei,
|
|
79
|
-
job_title: input.jobTitle,
|
|
80
|
-
task_definition_id: input.dynamicArgumentsScriptUrl ? 6 : 5,
|
|
81
|
-
custom: true,
|
|
82
|
-
time_frame: input.timeFrame,
|
|
83
|
-
recurring: input.recurring ?? false,
|
|
84
|
-
job_cost_prediction: jobCostPrediction,
|
|
85
|
-
timezone: input.timezone,
|
|
86
|
-
created_chain_id: input.chainId,
|
|
87
|
-
condition_type: input.conditionType,
|
|
88
|
-
upper_limit: input.upperLimit,
|
|
89
|
-
lower_limit: input.lowerLimit,
|
|
90
|
-
value_source_type: input.valueSourceType,
|
|
91
|
-
value_source_url: input.valueSourceUrl,
|
|
92
|
-
target_chain_id: input.chainId,
|
|
93
|
-
target_contract_address: input.targetContractAddress,
|
|
94
|
-
target_function: input.targetFunction,
|
|
95
|
-
abi: input.abi,
|
|
96
|
-
arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
97
|
-
arguments: input.arguments,
|
|
98
|
-
dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
|
|
99
|
-
is_imua: input.isImua ?? true,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// --- Encoding helpers for different job types ---
|
|
103
|
-
function encodeJobType1Data(timeInterval) {
|
|
104
|
-
return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [timeInterval]);
|
|
105
|
-
}
|
|
106
|
-
function encodeJobType2Data(timeInterval, ipfsHash) {
|
|
107
|
-
return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'bytes32'], [timeInterval, ipfsHash]);
|
|
108
|
-
}
|
|
109
|
-
function encodeJobType3or5Data(recurringJob) {
|
|
110
|
-
return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['bool'], [recurringJob]);
|
|
111
|
-
}
|
|
112
|
-
function encodeJobType4or6Data(recurringJob, ipfsHash) {
|
|
113
|
-
return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes32'], [recurringJob, ipfsHash]);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a job on the blockchain.
|
|
117
|
-
* @param client TriggerXClient instance
|
|
118
|
-
* @param params Parameters for creating the job
|
|
119
|
-
* @returns JobResponse containing the result of the job creation
|
|
120
|
-
*/
|
|
121
|
-
async function createJob(client, params) {
|
|
122
|
-
let { jobInput, signer, encodedData } = params;
|
|
123
|
-
if (!signer) {
|
|
124
|
-
throw new Error('A valid ethers.Signer must be provided to createJob');
|
|
125
|
-
}
|
|
126
|
-
// Use the API key from the client instance
|
|
127
|
-
const apiKey = client.getApiKey();
|
|
128
|
-
const userAddress = await signer.getAddress();
|
|
129
|
-
let jobTitle, timeFrame, targetContractAddress, jobType;
|
|
130
|
-
if ('jobTitle' in jobInput)
|
|
131
|
-
jobTitle = jobInput.jobTitle;
|
|
132
|
-
if ('timeFrame' in jobInput)
|
|
133
|
-
timeFrame = jobInput.timeFrame;
|
|
134
|
-
if ('targetContractAddress' in jobInput)
|
|
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
|
-
}
|
|
148
|
-
// Infer jobType from jobInput
|
|
149
|
-
if ('scheduleType' in jobInput) {
|
|
150
|
-
jobType = jobInput.dynamicArgumentsScriptUrl ? 2 : 1; // Time-based job
|
|
151
|
-
}
|
|
152
|
-
else if ('triggerChainId' in jobInput) {
|
|
153
|
-
jobType = jobInput.dynamicArgumentsScriptUrl ? 4 : 3; // Event-based job
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
jobType = jobInput.dynamicArgumentsScriptUrl ? 6 : 5; // Condition-based job
|
|
157
|
-
}
|
|
158
|
-
// --- Generate encodedData if not provided ---
|
|
159
|
-
if (!encodedData) {
|
|
160
|
-
// Time-based jobs
|
|
161
|
-
if ('scheduleType' in jobInput) {
|
|
162
|
-
if (jobType === 1) {
|
|
163
|
-
encodedData = encodeJobType1Data(jobInput.timeInterval ?? 0);
|
|
164
|
-
}
|
|
165
|
-
else if (jobType === 2) {
|
|
166
|
-
encodedData = encodeJobType2Data(jobInput.timeInterval ?? 0, jobInput.dynamicArgumentsScriptUrl || '');
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// Event-based jobs
|
|
170
|
-
else if ('triggerChainId' in jobInput) {
|
|
171
|
-
if (jobType === 3 || jobType === 5) {
|
|
172
|
-
encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
|
|
173
|
-
}
|
|
174
|
-
else if (jobType === 4 || jobType === 6) {
|
|
175
|
-
encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// Condition-based jobs
|
|
179
|
-
else {
|
|
180
|
-
if (jobType === 3 || jobType === 5) {
|
|
181
|
-
encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
|
|
182
|
-
}
|
|
183
|
-
else if (jobType === 4 || jobType === 6) {
|
|
184
|
-
encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// Handle job_cost_prediction logic based on argType (static/dynamic)
|
|
189
|
-
// If static, set to 0.1. If dynamic, call backend API to get fee and ask user to proceed.
|
|
190
|
-
// Determine argType directly from user input
|
|
191
|
-
let argType = 1; // default to static
|
|
192
|
-
if ('argType' in jobInput) {
|
|
193
|
-
if (jobInput.argType === 'dynamic' || jobInput.argType === 2) {
|
|
194
|
-
argType = 2;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
argType = 1;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
//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
|
|
201
|
-
let noOfExecutions = 1;
|
|
202
|
-
if ('scheduleType' in jobInput) {
|
|
203
|
-
noOfExecutions = jobInput.timeFrame / (jobInput.timeInterval ?? 0);
|
|
204
|
-
}
|
|
205
|
-
// Set job_cost_prediction
|
|
206
|
-
let job_cost_prediction = 0.1 * noOfExecutions; // default for static
|
|
207
|
-
if (argType === 2) {
|
|
208
|
-
// Dynamic: call backend API to get fee
|
|
209
|
-
const ipfs_url = jobInput.dynamicArgumentsScriptUrl;
|
|
210
|
-
if (!ipfs_url) {
|
|
211
|
-
throw new Error('dynamicArgumentsScriptUrl is required for dynamic argType');
|
|
212
|
-
}
|
|
213
|
-
// Call backend API to get fee
|
|
214
|
-
let fee = 0;
|
|
215
|
-
try {
|
|
216
|
-
const feeRes = await client.get('/api/fees', { params: { ipfs_url } });
|
|
217
|
-
// The API now returns { total_fee: number }
|
|
218
|
-
if (feeRes && typeof feeRes.total_fee === 'number') {
|
|
219
|
-
fee = feeRes.total_fee;
|
|
220
|
-
}
|
|
221
|
-
else if (feeRes && feeRes.data && typeof feeRes.data.total_fee === 'number') {
|
|
222
|
-
fee = feeRes.data.total_fee;
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
throw new Error('Invalid response from /api/fees: missing total_fee');
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch (err) {
|
|
229
|
-
throw new Error('Failed to fetch job cost prediction: ' + err.message);
|
|
230
|
-
}
|
|
231
|
-
job_cost_prediction = fee * noOfExecutions;
|
|
232
|
-
}
|
|
233
|
-
// Ask user if they want to proceed
|
|
234
|
-
// Since this is a library, we can't prompt in Node.js directly.
|
|
235
|
-
// We'll throw an error with the fee and let the caller handle the prompt/confirmation.
|
|
236
|
-
// If you want to automate, you can add a `proceed` flag to params in the future.
|
|
237
|
-
// Check if the user has enough TG to cover the job cost prediction
|
|
238
|
-
const { tgBalanceWei, tgBalance } = await (0, checkTgBalance_1.checkTgBalance)(signer);
|
|
239
|
-
if (Number(tgBalance) < job_cost_prediction) {
|
|
240
|
-
// Check if user has enabled auto topup
|
|
241
|
-
// For each job type, autotopupTG should be present in jobInput
|
|
242
|
-
const autoTopupTG = jobInput.autotopupTG === true;
|
|
243
|
-
if (!autoTopupTG) {
|
|
244
|
-
throw new Error(`Insufficient TG balance. Job cost prediction is ${job_cost_prediction}. Current TG balance: ${tgBalance}. Please set autotopupTG: true in jobInput.`);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
// autotopupTG is true, automatically top up
|
|
248
|
-
const requiredTG = Math.ceil(job_cost_prediction * 1000); // 1 TG = 0.001 ETH
|
|
249
|
-
await (0, topupTg_1.topupTg)(requiredTG, signer);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// Compute balances to store with the job
|
|
253
|
-
const tokenBalanceWei = tgBalanceWei;
|
|
254
|
-
const etherBalance = tokenBalanceWei / 1000n;
|
|
255
|
-
// Patch jobInput with job_cost_prediction for downstream usage
|
|
256
|
-
jobInput.jobCostPrediction = job_cost_prediction;
|
|
257
|
-
const jobId = await (0, JobRegistry_1.createJobOnChain)({
|
|
258
|
-
jobTitle: jobTitle,
|
|
259
|
-
jobType,
|
|
260
|
-
timeFrame: timeFrame,
|
|
261
|
-
targetContractAddress: targetContractAddress,
|
|
262
|
-
encodedData: encodedData || '',
|
|
263
|
-
contractAddress: JOB_REGISTRY_ADDRESS,
|
|
264
|
-
abi: JobRegistry_json_1.default.abi,
|
|
265
|
-
signer,
|
|
266
|
-
});
|
|
267
|
-
// 2. Convert input to CreateJobData
|
|
268
|
-
let jobData;
|
|
269
|
-
const balances = { etherBalance, tokenBalanceWei };
|
|
270
|
-
if ('scheduleType' in jobInput) {
|
|
271
|
-
jobData = toCreateJobDataFromTime(jobInput, balances, userAddress, job_cost_prediction);
|
|
272
|
-
}
|
|
273
|
-
else if ('triggerChainId' in jobInput) {
|
|
274
|
-
jobData = toCreateJobDataFromEvent(jobInput, balances, userAddress, job_cost_prediction);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
jobData = toCreateJobDataFromCondition(jobInput, balances, userAddress, job_cost_prediction);
|
|
278
|
-
}
|
|
279
|
-
// 3. Set the job_id from contract
|
|
280
|
-
jobData.job_id = jobId;
|
|
281
|
-
// 4. Call the API
|
|
282
|
-
try {
|
|
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], {
|
|
290
|
-
headers: { 'Content-Type': 'application/json', 'X-API-KEY': apiKey },
|
|
291
|
-
});
|
|
292
|
-
return { success: true, data: res };
|
|
293
|
-
}
|
|
294
|
-
catch (error) {
|
|
295
|
-
return { success: false, error: error.message };
|
|
296
|
-
}
|
|
297
|
-
}
|
package/dist/src/api/tasks.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { TriggerXClient } from '../client';
|
|
2
|
-
import { Task, ApiResponse } from '../types';
|
|
3
|
-
export declare function getTasks(client: TriggerXClient): Promise<ApiResponse<Task[]>>;
|
|
4
|
-
export declare function createTask(client: TriggerXClient, task: Partial<Task>): Promise<ApiResponse<Task>>;
|
package/dist/src/api/tasks.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTasks = getTasks;
|
|
4
|
-
exports.createTask = createTask;
|
|
5
|
-
async function getTasks(client) {
|
|
6
|
-
// Placeholder implementation
|
|
7
|
-
return client.get('/tasks');
|
|
8
|
-
}
|
|
9
|
-
async function createTask(client, task) {
|
|
10
|
-
// Placeholder implementation
|
|
11
|
-
// return client.post<ApiResponse<Task>>('/tasks', task);
|
|
12
|
-
return { data: { id: '1', name: task.name || '', status: 'pending', createdAt: new Date().toISOString() } };
|
|
13
|
-
}
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
export declare class TriggerXClient {
|
|
3
|
-
private client;
|
|
4
|
-
private apiKey;
|
|
5
|
-
constructor(apiKey: string, config?: AxiosRequestConfig);
|
|
6
|
-
getApiKey(): string;
|
|
7
|
-
get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
8
|
-
post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
9
|
-
put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
10
|
-
}
|
package/dist/src/client.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TriggerXClient = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const config_1 = require("./config");
|
|
9
|
-
class TriggerXClient {
|
|
10
|
-
constructor(apiKey, config) {
|
|
11
|
-
this.apiKey = apiKey; // Initialize the apiKey
|
|
12
|
-
const baseConfig = (0, config_1.getConfig)();
|
|
13
|
-
this.client = axios_1.default.create({
|
|
14
|
-
baseURL: config?.baseURL || baseConfig.apiUrl || 'https://data.triggerx.network', //http://localhost:9002 , https://data.triggerx.network
|
|
15
|
-
headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
|
|
16
|
-
...config,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// Method to get the API key
|
|
20
|
-
getApiKey() {
|
|
21
|
-
return this.apiKey;
|
|
22
|
-
}
|
|
23
|
-
async get(url, config) {
|
|
24
|
-
const response = await this.client.get(url, config);
|
|
25
|
-
return response.data;
|
|
26
|
-
}
|
|
27
|
-
async post(url, data, config) {
|
|
28
|
-
const response = await this.client.post(url, data, config);
|
|
29
|
-
return response.data;
|
|
30
|
-
}
|
|
31
|
-
// New PUT method
|
|
32
|
-
async put(url, data, config) {
|
|
33
|
-
const response = await this.client.put(url, data, config);
|
|
34
|
-
return response.data;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.TriggerXClient = TriggerXClient;
|
package/dist/src/config.d.ts
DELETED
package/dist/src/config.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfig = getConfig;
|
|
4
|
-
function getConfig() {
|
|
5
|
-
return {
|
|
6
|
-
apiKey: process.env.API_KEY || '',
|
|
7
|
-
apiUrl: process.env.API_URL || '',
|
|
8
|
-
contractAddress: process.env.CONTRACT_ADDRESS || '',
|
|
9
|
-
};
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Signer } from 'ethers';
|
|
2
|
-
export interface CreateJobOnChainParams {
|
|
3
|
-
jobTitle: string;
|
|
4
|
-
jobType: number;
|
|
5
|
-
timeFrame: number;
|
|
6
|
-
targetContractAddress: string;
|
|
7
|
-
encodedData: string;
|
|
8
|
-
contractAddress: string;
|
|
9
|
-
abi: any;
|
|
10
|
-
signer: Signer;
|
|
11
|
-
}
|
|
12
|
-
export declare function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, signer, }: CreateJobOnChainParams): Promise<string>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createJobOnChain = createJobOnChain;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
async function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, signer, }) {
|
|
6
|
-
const contract = new ethers_1.ethers.Contract(contractAddress, abi, signer);
|
|
7
|
-
const tx = await contract.createJob(jobTitle, jobType, timeFrame, targetContractAddress, encodedData);
|
|
8
|
-
const receipt = await tx.wait();
|
|
9
|
-
// Try to extract jobId from event logs (assume event is JobCreated(jobId,...))
|
|
10
|
-
const event = receipt.logs
|
|
11
|
-
.map((log) => {
|
|
12
|
-
try {
|
|
13
|
-
return contract.interface.parseLog(log);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
.find((e) => e && e.name === 'JobCreated');
|
|
20
|
-
if (event && event.args && event.args[0]) {
|
|
21
|
-
return event.args[0].toString();
|
|
22
|
-
}
|
|
23
|
-
throw new Error('Job ID not found in contract events');
|
|
24
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TriggerXContract = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
class TriggerXContract {
|
|
6
|
-
constructor(address, abi, provider) {
|
|
7
|
-
this.contract = new ethers_1.Contract(address, abi, provider);
|
|
8
|
-
}
|
|
9
|
-
async getTaskCount() {
|
|
10
|
-
// Placeholder for contract call
|
|
11
|
-
return this.contract.taskCount();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.TriggerXContract = TriggerXContract;
|