sdk-triggerx 0.1.30 → 0.1.32
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/README.md +9 -8
- package/dist/api/checkBalance.d.ts +33 -0
- package/dist/api/checkBalance.js +68 -0
- package/dist/api/jobs.d.ts +6 -2
- package/dist/api/jobs.js +174 -108
- package/dist/api/topup.d.ts +20 -0
- package/dist/api/topup.js +102 -0
- package/dist/api/topupTg.js +4 -2
- package/dist/api/withdraw.d.ts +26 -0
- package/dist/api/withdraw.js +89 -0
- package/dist/api/withdrawTg.js +24 -2
- package/dist/config.js +5 -5
- package/dist/contracts/JobRegistry.js +5 -5
- package/dist/contracts/abi/GasRegistry.json +268 -423
- package/dist/contracts/abi/JobRegistry.json +710 -1524
- package/dist/contracts/contractUtils.d.ts +13 -0
- package/dist/contracts/contractUtils.js +41 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/types.d.ts +32 -1
- package/dist/types.js +1 -0
- package/dist/utils/validation.d.ts +2 -2
- package/dist/utils/validation.js +63 -3
- package/package.json +1 -1
|
@@ -43,7 +43,20 @@ export declare function createContractWithSdkRpcAndSigner(contractAddress: strin
|
|
|
43
43
|
contract: Contract;
|
|
44
44
|
contractWithSigner: Contract;
|
|
45
45
|
chainId: string;
|
|
46
|
+
rpcProvider: ethers.JsonRpcProvider;
|
|
46
47
|
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Wait for a transaction receipt, falling back to eth_getTransactionReceipt if tx.wait fails
|
|
50
|
+
* This helps when the user's wallet/provider does not implement getTransactionReceipt properly.
|
|
51
|
+
* @param tx - Transaction response returned from contract call
|
|
52
|
+
* @param rpcProvider - SDK RPC provider that supports eth_getTransactionReceipt
|
|
53
|
+
* @param options - Optional polling configuration
|
|
54
|
+
* @returns Transaction receipt once available
|
|
55
|
+
*/
|
|
56
|
+
export declare function waitForTransactionReceiptWithRpcFallback(tx: ethers.ContractTransactionResponse, rpcProvider: ethers.JsonRpcProvider, options?: {
|
|
57
|
+
pollIntervalMs?: number;
|
|
58
|
+
maxAttempts?: number;
|
|
59
|
+
}): Promise<ethers.TransactionReceipt>;
|
|
47
60
|
/**
|
|
48
61
|
* Get contract address for a given chain ID
|
|
49
62
|
* @param chainId - Chain ID as string or number
|
|
@@ -4,6 +4,7 @@ exports.getSdkRpcProvider = getSdkRpcProvider;
|
|
|
4
4
|
exports.resolveChainId = resolveChainId;
|
|
5
5
|
exports.createContractWithSdkRpc = createContractWithSdkRpc;
|
|
6
6
|
exports.createContractWithSdkRpcAndSigner = createContractWithSdkRpcAndSigner;
|
|
7
|
+
exports.waitForTransactionReceiptWithRpcFallback = waitForTransactionReceiptWithRpcFallback;
|
|
7
8
|
exports.getContractAddress = getContractAddress;
|
|
8
9
|
const ethers_1 = require("ethers");
|
|
9
10
|
const config_1 = require("../config");
|
|
@@ -103,8 +104,48 @@ async function createContractWithSdkRpcAndSigner(contractAddress, abi, signer, c
|
|
|
103
104
|
contract,
|
|
104
105
|
contractWithSigner,
|
|
105
106
|
chainId: resolvedChainId,
|
|
107
|
+
rpcProvider,
|
|
106
108
|
};
|
|
107
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Wait for a transaction receipt, falling back to eth_getTransactionReceipt if tx.wait fails
|
|
112
|
+
* This helps when the user's wallet/provider does not implement getTransactionReceipt properly.
|
|
113
|
+
* @param tx - Transaction response returned from contract call
|
|
114
|
+
* @param rpcProvider - SDK RPC provider that supports eth_getTransactionReceipt
|
|
115
|
+
* @param options - Optional polling configuration
|
|
116
|
+
* @returns Transaction receipt once available
|
|
117
|
+
*/
|
|
118
|
+
async function waitForTransactionReceiptWithRpcFallback(tx, rpcProvider, options) {
|
|
119
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 3000;
|
|
120
|
+
const maxAttempts = options?.maxAttempts ?? 40;
|
|
121
|
+
try {
|
|
122
|
+
const directReceipt = await tx.wait();
|
|
123
|
+
if (directReceipt) {
|
|
124
|
+
return directReceipt;
|
|
125
|
+
}
|
|
126
|
+
console.warn(`tx.wait() returned null receipt for ${tx.hash}; falling back to eth_getTransactionReceipt via SDK RPC provider.`);
|
|
127
|
+
}
|
|
128
|
+
catch (waitError) {
|
|
129
|
+
console.warn('tx.wait() failed; falling back to eth_getTransactionReceipt via SDK RPC provider.', waitError);
|
|
130
|
+
}
|
|
131
|
+
const txHash = tx.hash;
|
|
132
|
+
if (!txHash) {
|
|
133
|
+
throw new Error('Transaction hash missing; cannot fetch receipt');
|
|
134
|
+
}
|
|
135
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
136
|
+
const receipt = await rpcProvider
|
|
137
|
+
.send('eth_getTransactionReceipt', [txHash])
|
|
138
|
+
.catch((rpcError) => {
|
|
139
|
+
console.warn('eth_getTransactionReceipt RPC call failed:', rpcError);
|
|
140
|
+
return null;
|
|
141
|
+
});
|
|
142
|
+
if (receipt) {
|
|
143
|
+
return receipt;
|
|
144
|
+
}
|
|
145
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`Transaction receipt not found for ${txHash} after ${maxAttempts} attempts using eth_getTransactionReceipt`);
|
|
148
|
+
}
|
|
108
149
|
/**
|
|
109
150
|
* Get contract address for a given chain ID
|
|
110
151
|
* @param chainId - Chain ID as string or number
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ export * from './types';
|
|
|
4
4
|
export * from './api/jobs';
|
|
5
5
|
export * from './api/getjob';
|
|
6
6
|
export * from './api/getUserData';
|
|
7
|
-
export * from './api/
|
|
8
|
-
export * from './api/
|
|
7
|
+
export * from './api/checkBalance';
|
|
8
|
+
export * from './api/topup';
|
|
9
|
+
export * from './api/withdraw';
|
|
9
10
|
export * from './api/deleteJob';
|
|
10
11
|
export * from './api/getJobDataById';
|
|
11
12
|
export * from './api/safeWallet';
|
package/dist/index.js
CHANGED
|
@@ -20,8 +20,9 @@ __exportStar(require("./types"), exports);
|
|
|
20
20
|
__exportStar(require("./api/jobs"), exports);
|
|
21
21
|
__exportStar(require("./api/getjob"), exports);
|
|
22
22
|
__exportStar(require("./api/getUserData"), exports);
|
|
23
|
-
__exportStar(require("./api/
|
|
24
|
-
__exportStar(require("./api/
|
|
23
|
+
__exportStar(require("./api/checkBalance"), exports);
|
|
24
|
+
__exportStar(require("./api/topup"), exports);
|
|
25
|
+
__exportStar(require("./api/withdraw"), exports);
|
|
25
26
|
__exportStar(require("./api/deleteJob"), exports);
|
|
26
27
|
__exportStar(require("./api/getJobDataById"), exports);
|
|
27
28
|
__exportStar(require("./api/safeWallet"), exports);
|
package/dist/types.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export type ApiResult<T> = SuccessResponse<T> | ErrorResponse;
|
|
|
26
26
|
export declare enum JobType {
|
|
27
27
|
Time = "time",
|
|
28
28
|
Event = "event",
|
|
29
|
-
Condition = "condition"
|
|
29
|
+
Condition = "condition",
|
|
30
|
+
CustomScript = "custom_script"
|
|
30
31
|
}
|
|
31
32
|
export declare enum ArgType {
|
|
32
33
|
Static = "static",
|
|
@@ -47,6 +48,9 @@ export type CreateJobInput = (TimeBasedJobInput & {
|
|
|
47
48
|
}) | (ConditionBasedJobInput & {
|
|
48
49
|
jobType: JobType.Condition;
|
|
49
50
|
argType: ArgType.Static | ArgType.Dynamic;
|
|
51
|
+
}) | (CustomScriptJobInput & {
|
|
52
|
+
jobType: JobType.CustomScript;
|
|
53
|
+
argType: ArgType.Dynamic;
|
|
50
54
|
});
|
|
51
55
|
export interface TimeBasedJobInput {
|
|
52
56
|
jobTitle: string;
|
|
@@ -63,6 +67,8 @@ export interface TimeBasedJobInput {
|
|
|
63
67
|
isImua?: boolean;
|
|
64
68
|
arguments?: string[];
|
|
65
69
|
dynamicArgumentsScriptUrl?: string;
|
|
70
|
+
autotopupETH?: boolean;
|
|
71
|
+
/** @deprecated Use autotopupETH instead */
|
|
66
72
|
autotopupTG?: boolean;
|
|
67
73
|
walletMode?: WalletMode;
|
|
68
74
|
safeName?: string;
|
|
@@ -95,6 +101,8 @@ export interface EventBasedJobInput {
|
|
|
95
101
|
isImua?: boolean;
|
|
96
102
|
arguments?: string[];
|
|
97
103
|
dynamicArgumentsScriptUrl?: string;
|
|
104
|
+
autotopupETH?: boolean;
|
|
105
|
+
/** @deprecated Use autotopupETH instead */
|
|
98
106
|
autotopupTG?: boolean;
|
|
99
107
|
walletMode?: WalletMode;
|
|
100
108
|
safeName?: string;
|
|
@@ -129,6 +137,8 @@ export interface ConditionBasedJobInput {
|
|
|
129
137
|
isImua?: boolean;
|
|
130
138
|
arguments?: string[];
|
|
131
139
|
dynamicArgumentsScriptUrl?: string;
|
|
140
|
+
autotopupETH?: boolean;
|
|
141
|
+
/** @deprecated Use autotopupETH instead */
|
|
132
142
|
autotopupTG?: boolean;
|
|
133
143
|
walletMode?: WalletMode;
|
|
134
144
|
safeName?: string;
|
|
@@ -146,6 +156,27 @@ export interface ConditionBasedJobInput {
|
|
|
146
156
|
*/
|
|
147
157
|
safeTransactions?: SafeTransaction[];
|
|
148
158
|
}
|
|
159
|
+
export interface CustomScriptJobInput {
|
|
160
|
+
jobTitle: string;
|
|
161
|
+
timeFrame: number;
|
|
162
|
+
timeInterval: number;
|
|
163
|
+
timezone: string;
|
|
164
|
+
chainId: string;
|
|
165
|
+
targetContractAddress?: string;
|
|
166
|
+
targetFunction?: string;
|
|
167
|
+
abi?: string;
|
|
168
|
+
isImua?: boolean;
|
|
169
|
+
arguments?: string[];
|
|
170
|
+
dynamicArgumentsScriptUrl: string;
|
|
171
|
+
autotopupETH?: boolean;
|
|
172
|
+
/** @deprecated Use autotopupETH instead */
|
|
173
|
+
autotopupTG?: boolean;
|
|
174
|
+
walletMode?: WalletMode;
|
|
175
|
+
safeName?: string;
|
|
176
|
+
language: string;
|
|
177
|
+
recurring?: boolean;
|
|
178
|
+
safeAddress?: string;
|
|
179
|
+
}
|
|
149
180
|
export interface CreateJobData {
|
|
150
181
|
job_id: string;
|
|
151
182
|
user_address: string;
|
package/dist/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TimeBasedJobInput, EventBasedJobInput, ConditionBasedJobInput } from '../types';
|
|
1
|
+
import { TimeBasedJobInput, EventBasedJobInput, ConditionBasedJobInput, CustomScriptJobInput } from '../types';
|
|
2
2
|
export declare function validateTimeBasedJobInput(input: TimeBasedJobInput, argType: 'static' | 'dynamic' | 1 | 2 | undefined): void;
|
|
3
3
|
export declare function validateEventBasedJobInput(input: EventBasedJobInput, argType: 'static' | 'dynamic' | 1 | 2 | undefined): void;
|
|
4
4
|
export declare function validateConditionBasedJobInput(input: ConditionBasedJobInput, argType: 'static' | 'dynamic' | 1 | 2 | undefined): void;
|
|
5
|
-
export declare function validateJobInput(jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput, argType?: 'static' | 'dynamic' | 1 | 2): void;
|
|
5
|
+
export declare function validateJobInput(jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput | CustomScriptJobInput, argType?: 'static' | 'dynamic' | 1 | 2): void;
|
package/dist/utils/validation.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.validateEventBasedJobInput = validateEventBasedJobInput;
|
|
|
5
5
|
exports.validateConditionBasedJobInput = validateConditionBasedJobInput;
|
|
6
6
|
exports.validateJobInput = validateJobInput;
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
|
+
const types_1 = require("../types");
|
|
8
9
|
const errors_1 = require("./errors");
|
|
9
10
|
function isNonEmptyString(value) {
|
|
10
11
|
return typeof value === 'string' && value.trim().length > 0;
|
|
@@ -278,14 +279,73 @@ function validateConditionBasedJobInput(input, argType) {
|
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
}
|
|
282
|
+
function validateCustomScriptJobInput(input) {
|
|
283
|
+
if (!isNonEmptyString(input.jobTitle)) {
|
|
284
|
+
throw new errors_1.ValidationError('jobTitle', 'Job title is required.');
|
|
285
|
+
}
|
|
286
|
+
if (!input.timeFrame || input.timeFrame <= 0) {
|
|
287
|
+
throw new errors_1.ValidationError('timeframe', 'Timeframe must be a positive number of seconds.');
|
|
288
|
+
}
|
|
289
|
+
if (!input.timeInterval || input.timeInterval <= 0) {
|
|
290
|
+
throw new errors_1.ValidationError('timeInterval', 'timeInterval is required and must be > 0 for custom script jobs.');
|
|
291
|
+
}
|
|
292
|
+
if (input.timeInterval > input.timeFrame) {
|
|
293
|
+
throw new errors_1.ValidationError('timeInterval', 'timeInterval cannot exceed the timeframe for custom script jobs.');
|
|
294
|
+
}
|
|
295
|
+
if (!isNonEmptyString(input.timezone)) {
|
|
296
|
+
throw new errors_1.ValidationError('timezone', 'Timezone is required.');
|
|
297
|
+
}
|
|
298
|
+
if (!isNonEmptyString(input.chainId)) {
|
|
299
|
+
throw new errors_1.ValidationError('chainId', 'Chain ID is required.');
|
|
300
|
+
}
|
|
301
|
+
if (!isNonEmptyString(input.dynamicArgumentsScriptUrl) || !isValidUrl(input.dynamicArgumentsScriptUrl)) {
|
|
302
|
+
throw new errors_1.ValidationError('contractIpfs', 'dynamicArgumentsScriptUrl is required and must be a valid URL for custom script jobs.');
|
|
303
|
+
}
|
|
304
|
+
if (!isNonEmptyString(input.language)) {
|
|
305
|
+
throw new errors_1.ValidationError('language', 'language is required for custom script jobs.');
|
|
306
|
+
}
|
|
307
|
+
// if (input.walletMode === 'safe') {
|
|
308
|
+
// if (input.safeTransactions && input.safeTransactions.length > 0) {
|
|
309
|
+
// throw new ValidationError('safeTransactions', 'Custom script jobs only support dynamic arguments; remove safeTransactions.');
|
|
310
|
+
// }
|
|
311
|
+
// } else {
|
|
312
|
+
// validateContractBasics(input.targetContractAddress, input.abi, input.targetFunction, 'contract');
|
|
313
|
+
// }
|
|
314
|
+
}
|
|
315
|
+
function isTimeBasedJobInput(jobInput) {
|
|
316
|
+
return jobInput && typeof jobInput === 'object' && 'scheduleType' in jobInput;
|
|
317
|
+
}
|
|
318
|
+
function isEventBasedJobInput(jobInput) {
|
|
319
|
+
return jobInput && typeof jobInput === 'object' && 'triggerChainId' in jobInput;
|
|
320
|
+
}
|
|
321
|
+
function isConditionBasedJobInput(jobInput) {
|
|
322
|
+
return jobInput && typeof jobInput === 'object' && 'conditionType' in jobInput;
|
|
323
|
+
}
|
|
324
|
+
function isCustomScriptJobInput(jobInput) {
|
|
325
|
+
if (!jobInput || typeof jobInput !== 'object') {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if ('scheduleType' in jobInput || 'triggerChainId' in jobInput || 'conditionType' in jobInput) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
return 'language' in jobInput && 'timeInterval' in jobInput && 'dynamicArgumentsScriptUrl' in jobInput;
|
|
332
|
+
}
|
|
281
333
|
function validateJobInput(jobInput, argType) {
|
|
282
|
-
if (
|
|
334
|
+
if (jobInput.jobType === types_1.JobType.CustomScript || isCustomScriptJobInput(jobInput)) {
|
|
335
|
+
validateCustomScriptJobInput(jobInput);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (isTimeBasedJobInput(jobInput)) {
|
|
283
339
|
validateTimeBasedJobInput(jobInput, argType);
|
|
340
|
+
return;
|
|
284
341
|
}
|
|
285
|
-
|
|
342
|
+
if (isEventBasedJobInput(jobInput)) {
|
|
286
343
|
validateEventBasedJobInput(jobInput, argType);
|
|
344
|
+
return;
|
|
287
345
|
}
|
|
288
|
-
|
|
346
|
+
if (isConditionBasedJobInput(jobInput)) {
|
|
289
347
|
validateConditionBasedJobInput(jobInput, argType);
|
|
348
|
+
return;
|
|
290
349
|
}
|
|
350
|
+
throw new errors_1.ValidationError('jobType', 'Unsupported job input payload.');
|
|
291
351
|
}
|