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
package/dist/api/jobs.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toCreateJobDataFromTime = toCreateJobDataFromTime;
|
|
4
|
-
exports.toCreateJobDataFromEvent = toCreateJobDataFromEvent;
|
|
5
|
-
exports.toCreateJobDataFromCondition = toCreateJobDataFromCondition;
|
|
6
|
-
exports.createJob = createJob;
|
|
7
|
-
const JobRegistry_1 = require("../contracts/JobRegistry");
|
|
8
|
-
const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
|
|
9
|
-
const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
|
|
10
|
-
function toCreateJobDataFromTime(input) {
|
|
11
|
-
return {
|
|
12
|
-
job_id: JOB_ID,
|
|
13
|
-
user_address: input.userAddress,
|
|
14
|
-
ether_balance: input.etherBalance,
|
|
15
|
-
token_balance: input.tokenBalance,
|
|
16
|
-
job_title: input.jobTitle,
|
|
17
|
-
task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
18
|
-
custom: true,
|
|
19
|
-
time_frame: input.timeFrame,
|
|
20
|
-
recurring: input.recurring ?? false,
|
|
21
|
-
job_cost_prediction: input.jobCostPrediction,
|
|
22
|
-
timezone: input.timezone,
|
|
23
|
-
created_chain_id: input.createdChainId,
|
|
24
|
-
schedule_type: input.scheduleType,
|
|
25
|
-
time_interval: input.timeInterval,
|
|
26
|
-
cron_expression: input.cronExpression,
|
|
27
|
-
specific_schedule: input.specificSchedule,
|
|
28
|
-
target_chain_id: input.targetChainId,
|
|
29
|
-
target_contract_address: input.targetContractAddress,
|
|
30
|
-
target_function: input.targetFunction,
|
|
31
|
-
abi: input.abi,
|
|
32
|
-
arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
33
|
-
arguments: input.arguments,
|
|
34
|
-
dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
|
|
35
|
-
is_imua: input.isImua ?? true,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function toCreateJobDataFromEvent(input) {
|
|
39
|
-
return {
|
|
40
|
-
job_id: JOB_ID,
|
|
41
|
-
user_address: input.userAddress,
|
|
42
|
-
ether_balance: input.etherBalance,
|
|
43
|
-
token_balance: input.tokenBalance,
|
|
44
|
-
job_title: input.jobTitle,
|
|
45
|
-
task_definition_id: input.dynamicArgumentsScriptUrl ? 4 : 3,
|
|
46
|
-
custom: true,
|
|
47
|
-
time_frame: input.timeFrame,
|
|
48
|
-
recurring: input.recurring ?? false,
|
|
49
|
-
job_cost_prediction: input.jobCostPrediction,
|
|
50
|
-
timezone: input.timezone,
|
|
51
|
-
created_chain_id: input.createdChainId,
|
|
52
|
-
trigger_chain_id: input.triggerChainId,
|
|
53
|
-
trigger_contract_address: input.triggerContractAddress,
|
|
54
|
-
trigger_event: input.triggerEvent,
|
|
55
|
-
target_chain_id: input.targetChainId,
|
|
56
|
-
target_contract_address: input.targetContractAddress,
|
|
57
|
-
target_function: input.targetFunction,
|
|
58
|
-
abi: input.abi,
|
|
59
|
-
arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
60
|
-
arguments: input.arguments,
|
|
61
|
-
dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
|
|
62
|
-
is_imua: input.isImua ?? true,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function toCreateJobDataFromCondition(input) {
|
|
66
|
-
return {
|
|
67
|
-
job_id: JOB_ID,
|
|
68
|
-
user_address: input.userAddress,
|
|
69
|
-
ether_balance: input.etherBalance,
|
|
70
|
-
token_balance: input.tokenBalance,
|
|
71
|
-
job_title: input.jobTitle,
|
|
72
|
-
task_definition_id: input.dynamicArgumentsScriptUrl ? 6 : 5,
|
|
73
|
-
custom: true,
|
|
74
|
-
time_frame: input.timeFrame,
|
|
75
|
-
recurring: input.recurring ?? false,
|
|
76
|
-
job_cost_prediction: input.jobCostPrediction,
|
|
77
|
-
timezone: input.timezone,
|
|
78
|
-
created_chain_id: input.createdChainId,
|
|
79
|
-
condition_type: input.conditionType,
|
|
80
|
-
upper_limit: input.upperLimit,
|
|
81
|
-
lower_limit: input.lowerLimit,
|
|
82
|
-
value_source_type: input.valueSourceType,
|
|
83
|
-
value_source_url: input.valueSourceUrl,
|
|
84
|
-
target_chain_id: input.targetChainId,
|
|
85
|
-
target_contract_address: input.targetContractAddress,
|
|
86
|
-
target_function: input.targetFunction,
|
|
87
|
-
abi: input.abi,
|
|
88
|
-
arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
|
|
89
|
-
arguments: input.arguments,
|
|
90
|
-
dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
|
|
91
|
-
is_imua: input.isImua ?? true,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async function createJob(client, params) {
|
|
95
|
-
// 1. Call contract to create job and get jobId
|
|
96
|
-
const { jobInput, privateKey, providerUrl, contractAddress, abi, encodedData, jobType } = params;
|
|
97
|
-
let jobTitle, timeFrame, targetContractAddress;
|
|
98
|
-
if ('jobTitle' in jobInput)
|
|
99
|
-
jobTitle = jobInput.jobTitle;
|
|
100
|
-
if ('timeFrame' in jobInput)
|
|
101
|
-
timeFrame = jobInput.timeFrame;
|
|
102
|
-
if ('targetContractAddress' in jobInput)
|
|
103
|
-
targetContractAddress = jobInput.targetContractAddress;
|
|
104
|
-
const jobId = await (0, JobRegistry_1.createJobOnChain)({
|
|
105
|
-
jobTitle: jobTitle,
|
|
106
|
-
jobType,
|
|
107
|
-
timeFrame: timeFrame,
|
|
108
|
-
targetContractAddress: targetContractAddress,
|
|
109
|
-
encodedData,
|
|
110
|
-
contractAddress,
|
|
111
|
-
abi,
|
|
112
|
-
privateKey,
|
|
113
|
-
providerUrl,
|
|
114
|
-
});
|
|
115
|
-
// 2. Convert input to CreateJobData
|
|
116
|
-
let jobData;
|
|
117
|
-
if ('scheduleType' in jobInput) {
|
|
118
|
-
jobData = toCreateJobDataFromTime(jobInput);
|
|
119
|
-
}
|
|
120
|
-
else if ('triggerChainId' in jobInput) {
|
|
121
|
-
jobData = toCreateJobDataFromEvent(jobInput);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
jobData = toCreateJobDataFromCondition(jobInput);
|
|
125
|
-
}
|
|
126
|
-
// 3. Set the job_id from contract
|
|
127
|
-
jobData.job_id = jobId;
|
|
128
|
-
// 4. Call the API
|
|
129
|
-
try {
|
|
130
|
-
const res = await client.post('/api/jobs', [jobData], {
|
|
131
|
-
headers: { 'Content-Type': 'application/json', 'X-API-KEY': 'ADMIN' },
|
|
132
|
-
});
|
|
133
|
-
return { success: true, data: res };
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
return { success: false, error: error.message };
|
|
137
|
-
}
|
|
138
|
-
}
|
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/client.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
export declare class TriggerXClient {
|
|
3
|
-
private client;
|
|
4
|
-
constructor(config?: AxiosRequestConfig);
|
|
5
|
-
get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
6
|
-
post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
7
|
-
}
|
package/dist/client.js
DELETED
|
@@ -1,27 +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(config) {
|
|
11
|
-
const baseConfig = (0, config_1.getConfig)();
|
|
12
|
-
this.client = axios_1.default.create({
|
|
13
|
-
baseURL: config?.baseURL || baseConfig.apiUrl || 'http://localhost:9002',
|
|
14
|
-
headers: { 'Authorization': `Bearer ${baseConfig.apiKey}` },
|
|
15
|
-
...config,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
async get(url, config) {
|
|
19
|
-
const response = await this.client.get(url, config);
|
|
20
|
-
return response.data;
|
|
21
|
-
}
|
|
22
|
-
async post(url, data, config) {
|
|
23
|
-
const response = await this.client.post(url, data, config);
|
|
24
|
-
return response.data;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.TriggerXClient = TriggerXClient;
|
package/dist/config.d.ts
DELETED
package/dist/config.js
DELETED
|
@@ -1,15 +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.getConfig = getConfig;
|
|
7
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
dotenv_1.default.config();
|
|
9
|
-
function getConfig() {
|
|
10
|
-
return {
|
|
11
|
-
apiKey: process.env.API_KEY || '',
|
|
12
|
-
apiUrl: process.env.API_URL || '',
|
|
13
|
-
contractAddress: process.env.CONTRACT_ADDRESS || '',
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface CreateJobOnChainParams {
|
|
2
|
-
jobTitle: string;
|
|
3
|
-
jobType: number;
|
|
4
|
-
timeFrame: number;
|
|
5
|
-
targetContractAddress: string;
|
|
6
|
-
encodedData: string;
|
|
7
|
-
contractAddress: string;
|
|
8
|
-
abi: any;
|
|
9
|
-
privateKey: string;
|
|
10
|
-
providerUrl: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, privateKey, providerUrl, }: CreateJobOnChainParams): Promise<string>;
|
|
@@ -1,26 +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, privateKey, providerUrl, }) {
|
|
6
|
-
const provider = new ethers_1.ethers.JsonRpcProvider(providerUrl);
|
|
7
|
-
const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
8
|
-
const contract = new ethers_1.ethers.Contract(contractAddress, abi, wallet);
|
|
9
|
-
const tx = await contract.createJob(jobTitle, jobType, timeFrame, targetContractAddress, encodedData);
|
|
10
|
-
const receipt = await tx.wait();
|
|
11
|
-
// Try to extract jobId from event logs (assume event is JobCreated(jobId,...))
|
|
12
|
-
const event = receipt.logs
|
|
13
|
-
.map((log) => {
|
|
14
|
-
try {
|
|
15
|
-
return contract.interface.parseLog(log);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
.find((e) => e && e.name === 'JobCreated');
|
|
22
|
-
if (event && event.args && event.args[0]) {
|
|
23
|
-
return event.args[0].toString();
|
|
24
|
-
}
|
|
25
|
-
throw new Error('Job ID not found in contract events');
|
|
26
|
-
}
|
|
@@ -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;
|