@cfxdevkit/executor 0.1.0 → 1.0.5

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.
Files changed (2) hide show
  1. package/README.md +132 -0
  2. package/package.json +24 -23
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @cfxdevkit/executor
2
+
3
+ On-chain strategy execution engine for Conflux DevKit — the runtime primitives for building keepers, bots, or AI agents that execute limit orders, DCA, TWAP, and spot swaps on Conflux eSpace.
4
+
5
+ ## Features
6
+
7
+ - **`Executor`** — Orchestrator that evaluates jobs on a tick interval, checks price conditions, enforces safety limits, and submits on-chain transactions.
8
+ - **`KeeperClientImpl`** — viem-based client that wraps the `AutomationManager` contract for job creation, cancellation, and forceful execution.
9
+ - **`SafetyGuard`** — Circuit-breaker with configurable per-tick swap caps, per-job retry caps, and a global circuit-breaker on consecutive failures.
10
+ - **`RetryQueue`** — Exponential backoff with jitter for failed job retries.
11
+ - **`PriceChecker`** — Pluggable price source interface + condition evaluator (`gte`/`lte` against a target price).
12
+ - **Full type system** — `Job` union type with per-strategy params (`LimitOrderJob`, `DCAJob`, `TWAPJob`, `SwapJob`) and lifecycle statuses.
13
+ - **Zero framework coupling** — Injectable `AutomationLogger` interface; no React, no HTTP framework required.
14
+
15
+ ## Supported strategies
16
+
17
+ | Strategy | Status |
18
+ |---|---|
19
+ | Limit order | ✅ Implemented |
20
+ | DCA (Dollar-Cost Averaging) | ✅ Implemented |
21
+ | TWAP | 🔜 Types only (contract support pending) |
22
+ | Spot swap | 🔜 Types only (contract support pending) |
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pnpm add @cfxdevkit/executor
28
+ # or
29
+ npm install @cfxdevkit/executor
30
+ ```
31
+
32
+ ## Peer dependencies
33
+
34
+ ```json
35
+ {
36
+ "viem": ">=2.0.0"
37
+ }
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Basic keeper setup
43
+
44
+ ```ts
45
+ import { Executor, KeeperClientImpl, SafetyGuard, PriceChecker, noopLogger } from '@cfxdevkit/executor';
46
+ import { createWalletClient, http } from 'viem';
47
+ import { confluxESpace } from 'viem/chains';
48
+ import { privateKeyToAccount } from 'viem/accounts';
49
+
50
+ const account = privateKeyToAccount('0x...');
51
+ const walletClient = createWalletClient({ account, chain: confluxESpace, transport: http() });
52
+
53
+ const keeperClient = new KeeperClientImpl({
54
+ walletClient,
55
+ automationManagerAddress: '0x...',
56
+ });
57
+
58
+ const safetyGuard = new SafetyGuard({
59
+ maxSwapsPerTick: 3,
60
+ maxConsecutiveFailures: 5,
61
+ maxRetriesPerJob: 4,
62
+ });
63
+
64
+ const priceChecker = new PriceChecker({
65
+ priceSource: myPriceSource, // implement PriceSource interface
66
+ decimalsResolver: myResolver, // implement DecimalsResolver interface
67
+ });
68
+
69
+ const executor = new Executor({
70
+ keeperClient,
71
+ safetyGuard,
72
+ priceChecker,
73
+ jobStore: myJobStore, // implement JobStore interface
74
+ logger: noopLogger, // or inject your own AutomationLogger
75
+ tickIntervalMs: 15_000, // evaluate jobs every 15 s
76
+ });
77
+
78
+ executor.start();
79
+ ```
80
+
81
+ ### Creating a limit order job
82
+
83
+ ```ts
84
+ import type { LimitOrderStrategy } from '@cfxdevkit/executor';
85
+
86
+ const strategy: LimitOrderStrategy = {
87
+ kind: 'limit_order',
88
+ tokenIn: '0xCFX...',
89
+ tokenOut: '0xUSDT...',
90
+ amountIn: '100.0', // human-readable
91
+ targetPrice: '0.38', // trigger when price >= target
92
+ direction: 'gte',
93
+ slippageBps: 50, // 0.5%
94
+ expiresInDays: 7,
95
+ };
96
+
97
+ await executor.createJob(strategy, ownerAddress);
98
+ ```
99
+
100
+ ### Creating a DCA job
101
+
102
+ ```ts
103
+ import type { DCAStrategy } from '@cfxdevkit/executor';
104
+
105
+ const strategy: DCAStrategy = {
106
+ kind: 'dca',
107
+ tokenIn: '0xUSDT...',
108
+ tokenOut: '0xCFX...',
109
+ amountPerSwap: '50.0', // human-readable, per interval
110
+ intervalHours: 24,
111
+ totalSwaps: 30,
112
+ slippageBps: 100, // 1%
113
+ };
114
+
115
+ await executor.createJob(strategy, ownerAddress);
116
+ ```
117
+
118
+ ## Job lifecycle
119
+
120
+ ```
121
+ pending → active → executed
122
+ ↘ failed (exhausted retries)
123
+ → cancelled (user-cancelled)
124
+ → paused (SafetyGuard circuit-breaker)
125
+ ```
126
+
127
+ ## Conflux Compatibility
128
+
129
+ | Network | Chain ID | Support |
130
+ |---|---|---|
131
+ | Conflux eSpace Mainnet | 1030 | ✅ |
132
+ | Conflux eSpace Testnet | 71 | ✅ |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfxdevkit/executor",
3
- "version": "0.1.0",
3
+ "version": "1.0.5",
4
4
  "description": "Conflux DevKit – on-chain strategy execution engine (limit orders, DCA, and more)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,10 +22,26 @@
22
22
  },
23
23
  "./package.json": "./package.json"
24
24
  },
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "build:watch": "tsup --watch",
28
+ "type-check": "tsc --noEmit",
29
+ "dev": "tsup --watch",
30
+ "test": "vitest run --pass-with-no-tests",
31
+ "test:run": "vitest --run",
32
+ "test:coverage": "vitest --run --coverage --pass-with-no-tests",
33
+ "clean": "rm -rf dist",
34
+ "lint": "biome lint src/",
35
+ "lint:fix": "biome lint --write src/",
36
+ "format": "biome format src/",
37
+ "format:fix": "biome format --write src/",
38
+ "check": "biome check src/",
39
+ "check:fix": "biome check --write src/"
40
+ },
25
41
  "dependencies": {
26
- "viem": ">=2.0.0",
27
- "@cfxdevkit/core": "0.1.0",
28
- "@cfxdevkit/protocol": "0.1.0"
42
+ "@cfxdevkit/core": "workspace:*",
43
+ "@cfxdevkit/protocol": "workspace:*",
44
+ "viem": ">=2.0.0"
29
45
  },
30
46
  "devDependencies": {
31
47
  "@biomejs/biome": "^2.3.10",
@@ -48,29 +64,14 @@
48
64
  ],
49
65
  "author": "Conflux DevKit Team",
50
66
  "license": "Apache-2.0",
67
+ "packageManager": "pnpm@10.11.0",
51
68
  "repository": {
52
69
  "type": "git",
53
- "url": "git+https://github.com/cfxdevkit/conflux-devkit.git",
70
+ "url": "git+https://github.com/cfxdevkit/devkit.git",
54
71
  "directory": "packages/executor"
55
72
  },
56
73
  "homepage": "https://github.com/cfxdevkit/conflux-devkit#readme",
57
74
  "bugs": {
58
- "url": "https://github.com/cfxdevkit/conflux-devkit/issues"
59
- },
60
- "scripts": {
61
- "build": "tsup",
62
- "build:watch": "tsup --watch",
63
- "type-check": "tsc --noEmit",
64
- "dev": "tsup --watch",
65
- "test": "vitest run --pass-with-no-tests",
66
- "test:run": "vitest --run",
67
- "test:coverage": "vitest --run --coverage",
68
- "clean": "rm -rf dist",
69
- "lint": "biome lint src/",
70
- "lint:fix": "biome lint --write src/",
71
- "format": "biome format src/",
72
- "format:fix": "biome format --write src/",
73
- "check": "biome check src/",
74
- "check:fix": "biome check --write src/"
75
+ "url": "https://github.com/cfxdevkit/devkit/issues"
75
76
  }
76
- }
77
+ }