sdk-triggerx 0.1.6 → 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/{src/api → api}/jobs.js +0 -3
- package/dist/{src/config.js → config.js} +5 -0
- package/package.json +15 -12
- package/.eslintrc.json +0 -16
- 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}/jobs.d.ts +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/client.d.ts → client.d.ts} +0 -0
- /package/dist/{src/client.js → client.js} +0 -0
- /package/dist/{src/config.d.ts → config.d.ts} +0 -0
- /package/dist/{src/contracts → contracts}/JobRegistry.d.ts +0 -0
- /package/dist/{src/contracts → contracts}/JobRegistry.js +0 -0
- /package/dist/{src/contracts → contracts}/TriggerXContract.d.ts +0 -0
- /package/dist/{src/contracts → contracts}/TriggerXContract.js +0 -0
- /package/dist/{src/contracts → contracts}/abi/GasRegistry.json +0 -0
- /package/dist/{src/contracts → contracts}/abi/JobRegistry.json +0 -0
- /package/dist/{src/contracts → contracts}/index.d.ts +0 -0
- /package/dist/{src/contracts → contracts}/index.js +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/index.js → index.js} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{src/types.js → types.js} +0 -0
- /package/dist/{src/utils → utils}/errors.d.ts +0 -0
- /package/dist/{src/utils → utils}/errors.js +0 -0
|
@@ -120,9 +120,6 @@ 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
|
-
}
|
|
126
123
|
// Use the API key from the client instance
|
|
127
124
|
const apiKey = client.getApiKey();
|
|
128
125
|
const userAddress = await signer.getAddress();
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getConfig = getConfig;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
dotenv_1.default.config();
|
|
4
9
|
function getConfig() {
|
|
5
10
|
return {
|
|
6
11
|
apiKey: process.env.API_KEY || '',
|
package/package.json
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"test": "jest",
|
|
10
|
-
"lint": "eslint src --ext .ts"
|
|
11
|
-
"example": "npm run -s build && node dist/test/createJobExample.js"
|
|
10
|
+
"lint": "eslint src --ext .ts"
|
|
12
11
|
},
|
|
13
|
-
"author": "",
|
|
12
|
+
"author": "Nipun Shah",
|
|
14
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"],
|
|
15
19
|
"directories": {
|
|
16
20
|
"test": "test"
|
|
17
21
|
},
|
|
18
|
-
"
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
19
25
|
"dependencies": {
|
|
20
|
-
"axios": "^1.11.0"
|
|
21
|
-
|
|
22
|
-
"peerDependencies": {
|
|
23
|
-
"ethers": ">=6 <7"
|
|
26
|
+
"axios": "^1.11.0",
|
|
27
|
+
"ethers": "^6.15.0"
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
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
|
-
"ethers": "^6.15.0",
|
|
31
35
|
"jest": "^30.0.5",
|
|
32
36
|
"ts-jest": "^29.4.0",
|
|
33
37
|
"typescript": "^5.8.3"
|
|
34
|
-
}
|
|
35
|
-
"sideEffects": false
|
|
38
|
+
}
|
|
36
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
4
|
-
const types_1 = require("../src/types");
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
|
-
async function main() {
|
|
7
|
-
const apiKey = 'TGRX-02c20872-4bdf-4fd9-9e74-556861b16690';
|
|
8
|
-
const client = new src_1.TriggerXClient(apiKey);
|
|
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
|
|
30
|
-
// const jobInput: CreateJobInput = {
|
|
31
|
-
// jobType: JobType.Condition,
|
|
32
|
-
// argType: ArgType.Static,
|
|
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',
|
|
40
|
-
// timezone: 'Asia/Calcutta',
|
|
41
|
-
// recurring: false,
|
|
42
|
-
// chainId: '11155420',
|
|
43
|
-
// targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
|
|
44
|
-
// targetFunction: 'incrementBy',
|
|
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"}]',
|
|
46
|
-
// isImua: true,
|
|
47
|
-
// arguments: ['5'],
|
|
48
|
-
// dynamicArgumentsScriptUrl: '',
|
|
49
|
-
// };
|
|
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
|
-
// };
|
|
65
|
-
// To test, you can call createJob with this input as well:
|
|
66
|
-
// const conditionResult = await createJob(client, {
|
|
67
|
-
// jobInput: conditionJobInput,
|
|
68
|
-
// signer,
|
|
69
|
-
// });
|
|
70
|
-
// console.log('Condition Job creation result:', conditionResult);
|
|
71
|
-
// These would typically come from env/config/user input
|
|
72
|
-
const privateKey = '0x3bd66a68dcde6ede3b38ced6de79489a447e0fac1648b749a5001b0aa167d089';
|
|
73
|
-
const providerUrl = 'https://arb-sepolia.g.alchemy.com/v2/zU9y7U094z69CQwzpro2mCKnW3A8gtlx';
|
|
74
|
-
const provider = new ethers_1.ethers.JsonRpcProvider(providerUrl);
|
|
75
|
-
const signer = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
76
|
-
console.log('Job input:', client);
|
|
77
|
-
const result = await (0, src_1.createJob)(client, {
|
|
78
|
-
jobInput: jobInput,
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
signer: signer,
|
|
81
|
-
});
|
|
82
|
-
console.log('Job creation result:', result);
|
|
83
|
-
}
|
|
84
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// sdk-triggerx/test/deleteJob.test.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const client_1 = require("../src/client");
|
|
5
|
-
const deleteJob_1 = require("../src/api/deleteJob");
|
|
6
|
-
async function main() {
|
|
7
|
-
// The user should provide their actual API key here
|
|
8
|
-
const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
|
|
9
|
-
// Create the client with the API key
|
|
10
|
-
const client = new client_1.TriggerXClient(apiKey);
|
|
11
|
-
// Specify the job ID to delete
|
|
12
|
-
const jobId = 'YOUR_JOB_ID'; // Replace with an actual job ID for testing
|
|
13
|
-
try {
|
|
14
|
-
// Call the SDK function to delete the job
|
|
15
|
-
await (0, deleteJob_1.deleteJob)(client, jobId);
|
|
16
|
-
console.log(`Job with ID ${jobId} deleted successfully.`);
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
console.error('Error deleting job:', error);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const errors_1 = require("../src/utils/errors");
|
|
4
|
-
describe('wrapError', () => {
|
|
5
|
-
it('should wrap a standard error', () => {
|
|
6
|
-
const err = new Error('fail');
|
|
7
|
-
const wrapped = (0, errors_1.wrapError)(err);
|
|
8
|
-
expect(wrapped).toBeInstanceOf(Error);
|
|
9
|
-
expect(wrapped.message).toBe('fail');
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// sdk-triggerx/test/getJobDataById.test.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const client_1 = require("../src/client");
|
|
5
|
-
const getJobDataById_1 = require("../src/api/getJobDataById");
|
|
6
|
-
async function main() {
|
|
7
|
-
// The user should provide their actual API key here
|
|
8
|
-
const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8'; // Use a mock API key
|
|
9
|
-
// Create the client with the API key
|
|
10
|
-
const client = new client_1.TriggerXClient(apiKey);
|
|
11
|
-
// Define a job ID for testing
|
|
12
|
-
const jobId = 'YOUR_JOB_ID'; // Replace with a valid job ID for testing
|
|
13
|
-
try {
|
|
14
|
-
// Call the SDK function to get job data
|
|
15
|
-
const response = await (0, getJobDataById_1.getJobDataById)(client, jobId);
|
|
16
|
-
// Log the response
|
|
17
|
-
console.log('Job Data:', response);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('Error fetching job data:', error);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// sdk-triggerx/test/getUserData.test.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const client_1 = require("../src/client");
|
|
5
|
-
const getUserData_1 = require("../src/api/getUserData");
|
|
6
|
-
async function main() {
|
|
7
|
-
// The user should provide their actual API key here
|
|
8
|
-
const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
|
|
9
|
-
// Create the client with the API key
|
|
10
|
-
const client = new client_1.TriggerXClient(apiKey);
|
|
11
|
-
// Specify the user address to fetch data for
|
|
12
|
-
const userAddress = 'YOUR_USER_ADDRESS'; // Replace with an actual user address for testing
|
|
13
|
-
try {
|
|
14
|
-
// Call the SDK function to get user data
|
|
15
|
-
const userData = await (0, getUserData_1.getUserData)(client, userAddress);
|
|
16
|
-
console.log('User Data:', userData);
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
console.error('Error fetching user data:', error);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/getjob.test.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_1 = require("../src/client");
|
|
4
|
-
const getjob_1 = require("../src/api/getjob");
|
|
5
|
-
async function main() {
|
|
6
|
-
// The user should provide their actual API key here
|
|
7
|
-
const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
|
|
8
|
-
// Create the client with the API key
|
|
9
|
-
const client = new client_1.TriggerXClient(apiKey);
|
|
10
|
-
// Call the SDK function to get job data
|
|
11
|
-
const response = await (0, getjob_1.getJobData)(client);
|
|
12
|
-
if (response.success) {
|
|
13
|
-
// Access job_data from the response
|
|
14
|
-
const jobData = response.jobs; // Use optional chaining in case job_data is undefined
|
|
15
|
-
console.log('Job Data:', jobData);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
console.error('Error fetching jobs:', response.error);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ethers_1 = require("ethers");
|
|
4
|
-
const topupTg_1 = require("../src/api/topupTg");
|
|
5
|
-
const checkTgBalance_1 = require("../src/api/checkTgBalance");
|
|
6
|
-
const withdrawTg_1 = require("../src/api/withdrawTg");
|
|
7
|
-
async function main() {
|
|
8
|
-
// Replace with your actual provider URL and private key
|
|
9
|
-
const providerUrl = 'https://opt-sepolia.g.alchemy.com/v2/m7cIDXzatSUYoiuE1xSY_TnUrK5j9-1W';
|
|
10
|
-
const privateKey = ''; // Replace with your private key
|
|
11
|
-
const provider = new ethers_1.ethers.JsonRpcProvider(providerUrl);
|
|
12
|
-
const signer = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
13
|
-
// Test the checkTgBalance function
|
|
14
|
-
try {
|
|
15
|
-
const balance = await (0, checkTgBalance_1.checkTgBalance)(signer);
|
|
16
|
-
console.log('TG Balance:', balance);
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
console.error('Error checking TG balance:', error);
|
|
20
|
-
}
|
|
21
|
-
// Test the topupTg function
|
|
22
|
-
const tgAmountToTopup = 1; // Amount of TG to purchase
|
|
23
|
-
try {
|
|
24
|
-
const txTopup = await (0, topupTg_1.topupTg)(tgAmountToTopup, signer);
|
|
25
|
-
console.log('Topup Transaction:', txTopup);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error('Error during topup:', error);
|
|
29
|
-
}
|
|
30
|
-
// Test the checkTgBalance function
|
|
31
|
-
try {
|
|
32
|
-
const balance = await (0, checkTgBalance_1.checkTgBalance)(signer);
|
|
33
|
-
console.log('TG Balance:', balance);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error('Error checking TG balance:', error);
|
|
37
|
-
}
|
|
38
|
-
// Test the withdrawTg function
|
|
39
|
-
const tgAmountToWithdraw = '1'; // Amount of TG to withdraw
|
|
40
|
-
try {
|
|
41
|
-
const txWithdraw = await (0, withdrawTg_1.withdrawTg)(signer, tgAmountToWithdraw);
|
|
42
|
-
console.log('Withdraw Transaction:', txWithdraw);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
console.error('Error during withdrawal:', error);
|
|
46
|
-
}
|
|
47
|
-
// Test the checkTgBalance function
|
|
48
|
-
try {
|
|
49
|
-
const balance = await (0, checkTgBalance_1.checkTgBalance)(signer);
|
|
50
|
-
console.log('TG Balance:', balance);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error('Error checking TG balance:', error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
main().catch(console.error);
|
package/jest.config.js
DELETED
package/scripts/deploy.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import gasRegistryAbi from '../contracts/abi/GasRegistry.json';
|
|
3
|
-
|
|
4
|
-
export const checkTgBalance = async (signer: ethers.Signer) => {
|
|
5
|
-
const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS as string || '0x85ea3eB894105bD7e7e2A8D34cf66C8E8163CD2a';
|
|
6
|
-
if (!gasRegistryContractAddress) {
|
|
7
|
-
throw new Error('GAS_REGISTRY_CONTRACT_ADDRESS is not set in the environment variables');
|
|
8
|
-
}
|
|
9
|
-
const contract = new ethers.Contract(gasRegistryContractAddress, gasRegistryAbi, signer);
|
|
10
|
-
const address = await signer.getAddress();
|
|
11
|
-
const balance = await contract.balances(address);
|
|
12
|
-
// balance is likely an array or object with ethSpent and TGbalance, both in wei
|
|
13
|
-
// We'll convert TGbalance from wei to ETH
|
|
14
|
-
// If balance is an array: [ethSpent, TGbalance]
|
|
15
|
-
// If balance is an object: { ethSpent, TGbalance }
|
|
16
|
-
let tgBalanceWei: bigint;
|
|
17
|
-
if (Array.isArray(balance)) {
|
|
18
|
-
tgBalanceWei = balance[1] as bigint;
|
|
19
|
-
} else if (balance && balance.TGbalance !== undefined) {
|
|
20
|
-
tgBalanceWei = balance.TGbalance as bigint;
|
|
21
|
-
} else {
|
|
22
|
-
throw new Error('Unexpected balance format');
|
|
23
|
-
}
|
|
24
|
-
const tgBalance = ethers.formatEther(tgBalanceWei);
|
|
25
|
-
console.log('tgBalanceEth', tgBalance);
|
|
26
|
-
return { tgBalanceWei, tgBalance };
|
|
27
|
-
};
|
package/src/api/deleteJob.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// sdk-triggerx/src/api/deleteJob.ts
|
|
2
|
-
|
|
3
|
-
import { TriggerXClient } from '../client';
|
|
4
|
-
|
|
5
|
-
export const deleteJob = async (client: TriggerXClient, jobId: string): Promise<void> => {
|
|
6
|
-
const apiKey = client.getApiKey(); // Assuming you have a method to get the API key
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
await client.put<void>(
|
|
10
|
-
`api/jobs/delete/${jobId}`, {},
|
|
11
|
-
{
|
|
12
|
-
headers: {
|
|
13
|
-
'Content-Type': 'application/json',
|
|
14
|
-
'X-API-KEY': apiKey,
|
|
15
|
-
},
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error('Error deleting job:', error);
|
|
20
|
-
throw error; // Rethrow the error for handling in the calling function
|
|
21
|
-
}
|
|
22
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// sdk-triggerx/src/api/getJobDataById.ts
|
|
2
|
-
|
|
3
|
-
import { TriggerXClient } from '../client';
|
|
4
|
-
import { JobDataAPI } from '../types';
|
|
5
|
-
|
|
6
|
-
export const getJobDataById = async (client: TriggerXClient, jobId: string): Promise<JobDataAPI> => {
|
|
7
|
-
const apiKey = client.getApiKey(); // Assuming you have a method to get the API key
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const response = await client.get<JobDataAPI>(
|
|
11
|
-
`/api/jobs/${jobId}`,
|
|
12
|
-
{
|
|
13
|
-
headers: {
|
|
14
|
-
'Content-Type': 'application/json',
|
|
15
|
-
'X-API-KEY': apiKey,
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
return response; // Assuming the response data matches the JobDataAPI interface
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.error('Error fetching job data by ID:', error);
|
|
22
|
-
throw error; // Rethrow the error for handling in the calling function
|
|
23
|
-
}
|
|
24
|
-
};
|
package/src/api/getUserData.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// sdk-triggerx/src/api/getUserData.ts
|
|
2
|
-
|
|
3
|
-
import { TriggerXClient } from '../client';
|
|
4
|
-
import { UserData } from '../types';
|
|
5
|
-
|
|
6
|
-
export const getUserData = async (client: TriggerXClient, address: string): Promise<UserData> => {
|
|
7
|
-
const apiKey = client.getApiKey(); // Assuming you have a method to get the API key
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const response = await client.get<UserData>(
|
|
11
|
-
`api/users/${address}`,
|
|
12
|
-
{
|
|
13
|
-
headers: {
|
|
14
|
-
'Content-Type': 'application/json',
|
|
15
|
-
'X-API-KEY': apiKey,
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
return response; // Assuming the response data matches the UserData interface
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.error('Error fetching user data:', error);
|
|
22
|
-
throw error; // Rethrow the error for handling in the calling function
|
|
23
|
-
}
|
|
24
|
-
};
|
package/src/api/getjob.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TriggerXClient } from '../client';
|
|
2
|
-
import { JobResponseUser, JobResponseAPI } from '../types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Fetch job data for a given API key by calling the backend endpoint.
|
|
6
|
-
* @param client TriggerXClient instance
|
|
7
|
-
* @returns JobResponse containing job data or error
|
|
8
|
-
*/
|
|
9
|
-
export async function getJobData(client: TriggerXClient): Promise<JobResponseUser> {
|
|
10
|
-
try {
|
|
11
|
-
|
|
12
|
-
const apiKey = client.getApiKey(); // Assuming you have a method to get the API key
|
|
13
|
-
const data = await client.get<JobResponseUser>(
|
|
14
|
-
'/api/jobs/by-apikey',
|
|
15
|
-
{
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
'X-API-KEY': apiKey,
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
return { success: true, jobs: data.jobs };
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return { success: false, error: (error as Error).message,};
|
|
25
|
-
}
|
|
26
|
-
}
|