sdk-triggerx 0.1.0
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/.eslintrc.json +16 -0
- package/README.md +249 -0
- package/dist/api/jobs.d.ts +15 -0
- package/dist/api/jobs.js +138 -0
- package/dist/api/tasks.d.ts +4 -0
- package/dist/api/tasks.js +13 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +27 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +15 -0
- package/dist/contracts/JobRegistry.d.ts +12 -0
- package/dist/contracts/JobRegistry.js +26 -0
- package/dist/contracts/TriggerXContract.d.ts +6 -0
- package/dist/contracts/TriggerXContract.js +14 -0
- package/dist/contracts/abi/JobRegistry.json +1554 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +17 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +26 -0
- package/dist/src/api/checkTgBalance.d.ts +2 -0
- package/dist/src/api/checkTgBalance.js +35 -0
- package/dist/src/api/deleteJob.d.ts +2 -0
- package/dist/src/api/deleteJob.js +20 -0
- package/dist/src/api/getJobDataById.d.ts +3 -0
- package/dist/src/api/getJobDataById.js +21 -0
- package/dist/src/api/getUserData.d.ts +3 -0
- package/dist/src/api/getUserData.js +21 -0
- package/dist/src/api/getjob.d.ts +8 -0
- package/dist/src/api/getjob.js +23 -0
- package/dist/src/api/jobs.d.ts +18 -0
- package/dist/src/api/jobs.js +270 -0
- package/dist/src/api/tasks.d.ts +4 -0
- package/dist/src/api/tasks.js +13 -0
- package/dist/src/api/topupTg.d.ts +2 -0
- package/dist/src/api/topupTg.js +19 -0
- package/dist/src/api/withdrawTg.d.ts +8 -0
- package/dist/src/api/withdrawTg.js +27 -0
- package/dist/src/client.d.ts +10 -0
- package/dist/src/client.js +37 -0
- package/dist/src/config.d.ts +6 -0
- package/dist/src/config.js +15 -0
- package/dist/src/contracts/JobRegistry.d.ts +12 -0
- package/dist/src/contracts/JobRegistry.js +24 -0
- package/dist/src/contracts/TriggerXContract.d.ts +6 -0
- package/dist/src/contracts/TriggerXContract.js +14 -0
- package/dist/src/contracts/abi/GasRegistry.json +607 -0
- package/dist/src/contracts/abi/JobRegistry.json +1554 -0
- package/dist/src/contracts/index.d.ts +1 -0
- package/dist/src/contracts/index.js +17 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +25 -0
- package/dist/src/types.d.ts +246 -0
- package/dist/src/types.js +15 -0
- package/dist/src/utils/errors.d.ts +4 -0
- package/dist/src/utils/errors.js +17 -0
- package/dist/test/createJobExample.d.ts +1 -0
- package/dist/test/createJobExample.js +77 -0
- package/dist/test/deleteJob.test.d.ts +1 -0
- package/dist/test/deleteJob.test.js +22 -0
- package/dist/test/example.test.d.ts +1 -0
- package/dist/test/example.test.js +11 -0
- package/dist/test/getJobDataById.test.d.ts +1 -0
- package/dist/test/getJobDataById.test.js +23 -0
- package/dist/test/getUserData.test.d.ts +1 -0
- package/dist/test/getUserData.test.js +22 -0
- package/dist/test/getjob.test.d.ts +1 -0
- package/dist/test/getjob.test.js +21 -0
- package/dist/test/testTgFunctions.d.ts +1 -0
- package/dist/test/testTgFunctions.js +56 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.js +15 -0
- package/dist/utils/errors.d.ts +4 -0
- package/dist/utils/errors.js +17 -0
- package/jest.config.js +7 -0
- package/package.json +32 -0
- package/scripts/deploy.ts +9 -0
- package/src/api/checkTgBalance.ts +27 -0
- package/src/api/deleteJob.ts +22 -0
- package/src/api/getJobDataById.ts +24 -0
- package/src/api/getUserData.ts +24 -0
- package/src/api/getjob.ts +26 -0
- package/src/api/jobs.ts +303 -0
- package/src/api/topupTg.ts +17 -0
- package/src/api/withdrawTg.ts +25 -0
- package/src/client.ts +38 -0
- package/src/config.ts +16 -0
- package/src/contracts/JobRegistry.ts +45 -0
- package/src/contracts/TriggerXContract.ts +14 -0
- package/src/contracts/abi/.gitkeep +1 -0
- package/src/contracts/abi/GasRegistry.json +607 -0
- package/src/contracts/abi/JobRegistry.json +1554 -0
- package/src/contracts/index.ts +1 -0
- package/src/index.ts +7 -0
- package/src/types.ts +262 -0
- package/src/utils/errors.ts +13 -0
- package/test/createJobExample.ts +84 -0
- package/test/deleteJob.test.ts +25 -0
- package/test/example.test.d.ts +1 -0
- package/test/example.test.js +11 -0
- package/test/example.test.ts +10 -0
- package/test/getJobDataById.test.ts +27 -0
- package/test/getUserData.test.ts +25 -0
- package/test/getjob.test.ts +23 -0
- package/test/testTgFunctions.ts +56 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import gasRegistryAbi from '../contracts/abi/GasRegistry.json';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Withdraw ETH in exchange for TG tokens.
|
|
6
|
+
* @param signer ethers.Signer instance
|
|
7
|
+
* @param amountTG The amount of TG tokens to withdraw (as a string or BigNumberish)
|
|
8
|
+
* @returns The transaction object
|
|
9
|
+
*/
|
|
10
|
+
export const withdrawTg = async (
|
|
11
|
+
signer: ethers.Signer,
|
|
12
|
+
amountTG: string | ethers.BigNumberish
|
|
13
|
+
) => {
|
|
14
|
+
const gasRegistryContractAddress = process.env.GAS_REGISTRY_CONTRACT_ADDRESS as string || '0x85ea3eB894105bD7e7e2A8D34cf66C8E8163CD2a';
|
|
15
|
+
if (!gasRegistryContractAddress) {
|
|
16
|
+
throw new Error('GAS_REGISTRY_CONTRACT_ADDRESS is not set in the environment variables');
|
|
17
|
+
}
|
|
18
|
+
const contract = new ethers.Contract(gasRegistryContractAddress, gasRegistryAbi, signer);
|
|
19
|
+
|
|
20
|
+
// Assumes the contract has a function: claimEthForTg(uint256 amount)
|
|
21
|
+
const amountTGWei = ethers.parseEther(amountTG.toString());
|
|
22
|
+
const tx = await contract.claimETHForTG(amountTGWei);
|
|
23
|
+
await tx.wait();
|
|
24
|
+
return tx;
|
|
25
|
+
};
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { getConfig } from './config';
|
|
3
|
+
|
|
4
|
+
export class TriggerXClient {
|
|
5
|
+
private client: AxiosInstance;
|
|
6
|
+
private apiKey: string; // Store the API key
|
|
7
|
+
|
|
8
|
+
constructor(apiKey: string, config?: AxiosRequestConfig) {
|
|
9
|
+
this.apiKey = apiKey; // Initialize the apiKey
|
|
10
|
+
const baseConfig = getConfig();
|
|
11
|
+
this.client = axios.create({
|
|
12
|
+
baseURL: config?.baseURL || baseConfig.apiUrl || 'http://localhost:9002',
|
|
13
|
+
headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
|
|
14
|
+
...config,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Method to get the API key
|
|
19
|
+
getApiKey(): string {
|
|
20
|
+
return this.apiKey;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
|
24
|
+
const response = await this.client.get<T>(url, config);
|
|
25
|
+
return response.data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
|
|
29
|
+
const response = await this.client.post<T>(url, data, config);
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// New PUT method
|
|
34
|
+
async put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
|
|
35
|
+
const response = await this.client.put<T>(url, data, config);
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
export interface SDKConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
apiUrl: string;
|
|
7
|
+
contractAddress: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getConfig(): SDKConfig {
|
|
11
|
+
return {
|
|
12
|
+
apiKey: process.env.API_KEY || '',
|
|
13
|
+
apiUrl: process.env.API_URL || '',
|
|
14
|
+
contractAddress: process.env.CONTRACT_ADDRESS || '',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ethers, Signer } from 'ethers';
|
|
2
|
+
|
|
3
|
+
export interface CreateJobOnChainParams {
|
|
4
|
+
jobTitle: string;
|
|
5
|
+
jobType: number;
|
|
6
|
+
timeFrame: number;
|
|
7
|
+
targetContractAddress: string;
|
|
8
|
+
encodedData: string;
|
|
9
|
+
contractAddress: string;
|
|
10
|
+
abi: any;
|
|
11
|
+
signer: Signer;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function createJobOnChain({
|
|
15
|
+
jobTitle,
|
|
16
|
+
jobType,
|
|
17
|
+
timeFrame,
|
|
18
|
+
targetContractAddress,
|
|
19
|
+
encodedData,
|
|
20
|
+
contractAddress,
|
|
21
|
+
abi,
|
|
22
|
+
signer,
|
|
23
|
+
}: CreateJobOnChainParams): Promise<string> {
|
|
24
|
+
const contract = new ethers.Contract(contractAddress, abi, signer);
|
|
25
|
+
|
|
26
|
+
const tx = await contract.createJob(jobTitle, jobType, timeFrame, targetContractAddress, encodedData);
|
|
27
|
+
const receipt = await tx.wait();
|
|
28
|
+
|
|
29
|
+
// Try to extract jobId from event logs (assume event is JobCreated(jobId,...))
|
|
30
|
+
const event = receipt.logs
|
|
31
|
+
.map((log: any) => {
|
|
32
|
+
try {
|
|
33
|
+
return contract.interface.parseLog(log);
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.find((e: any) => e && e.name === 'JobCreated');
|
|
39
|
+
|
|
40
|
+
if (event && event.args && event.args[0]) {
|
|
41
|
+
return event.args[0].toString();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error('Job ID not found in contract events');
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Contract, Provider } from 'ethers';
|
|
2
|
+
|
|
3
|
+
export class TriggerXContract {
|
|
4
|
+
private contract: Contract;
|
|
5
|
+
|
|
6
|
+
constructor(address: string, abi: any, provider: Provider) {
|
|
7
|
+
this.contract = new Contract(address, abi, provider);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async getTaskCount(): Promise<number> {
|
|
11
|
+
// Placeholder for contract call
|
|
12
|
+
return this.contract.taskCount();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|