@orbs-network/spot 2.11.0 → 2.11.3

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 (18) hide show
  1. package/README.md +22 -244
  2. package/config.json +39 -2
  3. package/out/06_DeployApprovalAdapter.s.sol/DeployApprovalAdapter.abi.json +28 -0
  4. package/out/ApprovalDexAdapter.sol/ApprovalDexAdapter.abi.json +471 -0
  5. package/out/ApprovalDexAdapter.t.sol/ApprovalDexAdapterTest.abi.json +929 -0
  6. package/out/Settler.t.sol/VmContractHelper154.abi.json +233 -0
  7. package/package.json +1 -1
  8. /package/out/{BaseTest.sol/VmContractHelper115.abi.json → ApprovalDexAdapter.t.sol/VmContractHelper122.abi.json} +0 -0
  9. /package/out/{CosignerIntegration.t.sol/VmContractHelper120.abi.json → BaseTest.sol/VmContractHelper117.abi.json} +0 -0
  10. /package/out/{DefaultDexAdapter.t.sol/VmContractHelper123.abi.json → CosignerIntegration.t.sol/VmContractHelper127.abi.json} +0 -0
  11. /package/out/{DynamicP2DexAdapter.t.sol/VmContractHelper125.abi.json → DefaultDexAdapter.t.sol/VmContractHelper129.abi.json} +0 -0
  12. /package/out/{Executor.t.sol → DynamicP2DexAdapter.t.sol}/VmContractHelper131.abi.json +0 -0
  13. /package/out/{OrderReactor.E2E.t.sol/VmContractHelper134.abi.json → Executor.t.sol/VmContractHelper136.abi.json} +0 -0
  14. /package/out/{P2DexAdapter.t.sol → OrderReactor.E2E.t.sol}/VmContractHelper139.abi.json +0 -0
  15. /package/out/OrderReactorPause.t.sol/{VmContractHelper135.abi.json → VmContractHelper140.abi.json} +0 -0
  16. /package/out/{ParaswapDexAdapter.t.sol/VmContractHelper142.abi.json → P2DexAdapter.t.sol/VmContractHelper144.abi.json} +0 -0
  17. /package/out/{Refinery.t.sol → ParaswapDexAdapter.t.sol}/VmContractHelper145.abi.json +0 -0
  18. /package/out/{Settler.t.sol/VmContractHelper151.abi.json → Refinery.t.sol/VmContractHelper148.abi.json} +0 -0
package/README.md CHANGED
@@ -1,258 +1,36 @@
1
- # Spot — Limit, TWAP, Stop-Loss, Take-Profit Non-Custodial Decentralized DeFi Protocol
1
+ # Spot
2
2
 
3
- **Agent-ready decentralized DeFi protocol for non-custodial advanced order types on EVM chains.**
3
+ Non-custodial market, limit, TWAP, stop-loss, take-profit, and delayed-start orders on EVM chains.
4
4
 
5
- Spot provides non-custodial market, limit, TWAP, stop-loss, take-profit, and delayed-start orders on EVM chains, backed by immutable onchain contracts.
5
+ ## 💱 Order Types
6
6
 
7
- **🔒 Security Audit Reports:** [Initial AstraSec audit](./Audit-AstraSec.pdf) and [updated AstraSec audit](./Audit2-AstraSec.pdf)
7
+ 1. **Market**: Swap at the current price within your slippage limit.
8
+ 2. **Limit**: Swap only when your minimum output can be met.
9
+ 3. **TWAP**: Split a total amount into equal chunks at regular intervals.
10
+ 4. **Stop-loss**: Trigger a swap when the price falls below your threshold.
11
+ 5. **Take-profit**: Trigger a swap when the price rises above your threshold.
12
+ 6. **Delayed start**: Schedule when your order becomes eligible.
8
13
 
9
- ## Why Spot
14
+ ## ⚙️ How It Works
10
15
 
11
- 1. ✅ **Non-custodial**: RePermit binds spend authorization to exact order hashes instead of handing custody to the protocol.
12
- 2. 🔒 **Oracle-protected**: Trigger checks, slippage caps, freshness windows, and deadlines constrain execution.
13
- 3. 🛡️ **Battle-tested**: Contracts are audited and covered by an extensive Foundry test suite.
14
- 4. 🏗️ **Production-ready**: Spot is built for multi-chain deployment with repo-shipped config, ABIs, skill files, and a hosted MCP endpoint.
16
+ Choose your tokens, total amount, price conditions, and expiration. For recurring orders, set the chunk size and interval. Sign the order; executors fill it when its conditions are met.
15
17
 
16
- ## Supported Order Types
18
+ Your funds remain in your wallet until execution. Price checks, slippage limits, and expiration constrain each fill.
17
19
 
18
- 1. Market swaps
19
- 2. Limit orders
20
- 3. TWAP orders
21
- 4. Stop-loss orders
22
- 5. Take-profit orders
23
- 6. Delayed-start orders
24
- 7. Chunked recurring execution
20
+ ## 🌐 Supported Chains
25
21
 
26
- ## Supported Chains
22
+ See [supported chains](./skill/SKILL.md#supported-chains) and [contract addresses](./config.json).
27
23
 
28
- Spot supports multiple EVM chains. See [`config.json`](./config.json) for supported chain configurations and runtime addresses, and [`skill/SKILL.md`](./skill/SKILL.md#supported-chains) for chains supporting order execution.
24
+ ## 🚀 Get Started
29
25
 
30
- Run `t` before local order QA. `npm test` includes `npm run test:e2e`, a read-only live dependency check using `chain`, `cast`, `jq`, `curl`, and GNU `parallel`. It fetches the current production [offchain oracle config](https://github.com/orbs-network/offchain-oracle/blob/master/config.json) once per run and reports the union of Spot config, skill chains, and oracle chains in a coverage table. `npm run test:e2e -- 1` scopes the report to Ethereum.
26
+ 1. **AI agents**: Use the [Spot Advanced Swap Orders skill](./skill/SKILL.md), available on [Clawhub](https://clawhub.ai/eranp-orbs/spot-advanced-swap-orders), or connect to the [hosted MCP endpoint](https://agents-sink.orbs.network/mcp).
27
+ 2. **Integrators**: Follow the [API, TypeScript, React, and swap-routing guides](https://spot-integration-docs.vercel.app/).
28
+ 3. **Support**: [Report a bug or request a feature](https://github.com/orbs-network/spot/issues).
31
29
 
32
- Every explicit Spot chain must have all six core contracts, a deployed USD oracle and aggregator, deployed and registered oracle adapters, the correct oracle-to-aggregator binding, and positive USD quotes for native, wrapped native, and all configured oracle connectors. Execution chains additionally require the existing solver and integration checks. Missing config, contracts, quotes, or RPC access fail the test with visible details. Oracle-only chains show core discovery and configured oracle coverage; a complete Spot core deployment without an explicit Spot entry also fails. Discovery is limited to the selected config/skill/oracle chain set, not every EVM network. `SPOT_ORACLE_CONFIG_JSON` can supply an explicit oracle config snapshot for reproducible diagnostics; normal tests fetch production directly.
30
+ ## 🔒 Security
33
31
 
34
- Orvex uses Spot's universal integration on Robinhood Chain (`4663`), with execution routing selected at fill time. No other Orvex mainnet deployment is listed in its [official contract directory](https://docs.orvex.fi/developer-resources/contract-addresses).
32
+ Spot's contracts were audited by AstraSec: [initial audit](./Audit-AstraSec.pdf) and [updated audit](./Audit2-AstraSec.pdf).
35
33
 
36
- Robinhood's solver adapters cover Kyber, Flytrade (`Magpie`), OpenOcean, and LI.FI (`LiFi`).
34
+ ## 📄 License
37
35
 
38
- ## How It Works
39
-
40
- Each Spot order combines timing, sizing, trigger, and settlement rules in a single signed payload.
41
-
42
- 1. `input.amount` is the per-fill chunk size.
43
- 2. `input.maxAmount` is the total budget across fills.
44
- 3. `output.limit` is the minimum acceptable output per chunk.
45
- 4. `output.triggerLower` and `output.triggerUpper` define stop-loss and take-profit style trigger bands.
46
- 5. `epoch` controls recurrence: `0` for one-shot, `> 0` for recurring fills.
47
- 6. `start` and `deadline` define the execution window.
48
-
49
- `output.limit`, `triggerLower`, and `triggerUpper` are encoded as per-chunk output-token amounts in the output token's decimals.
50
-
51
- A typical order lifecycle is:
52
-
53
- 1. **Order creation**: The user signs one EIP-712 order with chunk size, total amount, limits, slippage tolerance, epoch interval, and deadline.
54
- 2. **Price attestation**: The cosigner signs both trigger-time and current market price data.
55
- 3. **Execution trigger**: A whitelisted executor calls `Executor.execute()` when the order is eligible.
56
- 4. **Validation**: `OrderReactor` validates signatures, checks `start`, enforces epoch windows, verifies timestamps, and applies slippage protection.
57
- 5. **Settlement**: The reactor transfers input tokens, validates the fill result, and enforces minimum output.
58
- 6. **Distribution**: Surplus output is distributed between the swapper and optional referrer according to configured shares.
59
-
60
- ## Security
61
-
62
- Spot's contracts were professionally audited by AstraSec. See the **[initial security audit report](./Audit-AstraSec.pdf)** and **[updated security audit report](./Audit2-AstraSec.pdf)**.
63
- Spot is also oracle-protected: execution depends on cosigned trigger and market price data, freshness windows, and slippage checks.
64
-
65
- ### Access Controls
66
-
67
- 1. **WM Allowlist**: WM-gated entrypoints restrict privileged admin operations, and order execution honors exclusivity rules.
68
- 2. **Two-Step Ownership**: `WM` uses OpenZeppelin `Ownable2Step` for secure ownership transfers.
69
- 3. **Executor Binding**: Orders specify an authorized executor; only that executor can fill the order.
70
- 4. **Non-Exclusive Fillers**: `exclusivity = 0` locks fills to the designated executor, while values above zero allow third-party fillers that satisfy the higher minimum output requirement.
71
-
72
- ### Validation Layers
73
-
74
- 1. **Order Validation**: `OrderValidationLib.validate()` checks all order fields for validity.
75
- 2. **Signature Verification**: RePermit validates EIP-712 signatures and witness data binding.
76
- 3. **Oracle Price Attestation**: The cosigner supplies trigger-time and current market price data used to gate execution.
77
- 4. **Epoch Enforcement**: `EpochLib.update()` prevents early or duplicate fills within time windows.
78
- 5. **Slippage Protection**: A maximum 50% slippage cap is enforced in `src/Constants.sol`.
79
- 6. **Freshness Windows**: Current cosignatures expire after configurable time periods.
80
- 7. **Trigger Timestamp Rules**: Trigger timestamps must be after `start` and no later than the current timestamp.
81
-
82
- ### Economic Security
83
-
84
- 1. **Witness-Bound Spending**: RePermit ties allowances to exact order hashes, preventing signature reuse.
85
- 2. **Surplus Distribution**: Excess tokens are distributed between the swapper and referrer.
86
- 3. **Exact Allowances**: `SafeERC20.forceApprove()` avoids allowance accumulation attacks.
87
-
88
- ### Operational Security
89
-
90
- 1. **Reentrancy Protection**: `OrderReactor` uses `ReentrancyGuard`; `Executor` and `Refinery` rely on WM gating and internal invariants.
91
- 2. **Safe Token Handling**: The system supports USDT-like tokens and ETH handling semantics.
92
- 3. **Emergency Pause**: `OrderReactor` can be paused by WM-allowed addresses.
93
-
94
- ## Examples
95
-
96
- Plain-English examples:
97
-
98
- 1. Sell a fixed amount once, but only if the execution meets a minimum output.
99
- 2. Split a larger budget into equal chunks and execute one chunk every hour as a TWAP.
100
- 3. Move into a safer asset if price falls below a stop-loss threshold, or exit on strength if a take-profit threshold is reached.
101
-
102
- ### Single-Shot Limit Order
103
-
104
- ```solidity
105
- Order memory order = Order({
106
- // ... standard fields
107
- epoch: 0, // Single execution
108
- input: Input({
109
- amount: 1000e6, // Exact amount to spend
110
- maxAmount: 1000e6 // Same as amount
111
- }),
112
- output: Output({
113
- limit: 950 ether, // Minimum acceptable output
114
- triggerLower: 0, // No lower trigger gate
115
- triggerUpper: 0 // No upper trigger gate
116
- })
117
- });
118
- ```
119
-
120
- ### TWAP Order
121
-
122
- ```solidity
123
- Order memory order = Order({
124
- // ... standard fields
125
- epoch: 3600, // Execute every hour
126
- input: Input({
127
- amount: 100e6, // 100 USDC per chunk
128
- maxAmount: 1000e6 // 1000 USDC total budget
129
- }),
130
- output: Output({
131
- limit: 95 ether, // Minimum per chunk
132
- triggerLower: 0,
133
- triggerUpper: 0
134
- })
135
- });
136
- ```
137
-
138
- ### Stop-Loss / Take-Profit Order
139
-
140
- ```solidity
141
- Order memory order = Order({
142
- // ... standard fields
143
- epoch: 0, // Single execution
144
- start: block.timestamp, // Order becomes active immediately
145
- output: Output({
146
- limit: 900 ether, // Minimum per chunk output when executing
147
- triggerLower: 950 ether, // Stop-loss boundary per chunk
148
- triggerUpper: 1200 ether // Take-profit boundary per chunk
149
- })
150
- });
151
- ```
152
-
153
- ## Technical Overview
154
-
155
- ### Core Components
156
-
157
- 1. 🧠 **OrderReactor** (`src/OrderReactor.sol`): Validates orders, checks epoch constraints, computes minimum output from cosigned prices, settles via inlined implementation with reentrancy protection, and supports emergency pause via the WM allowlist.
158
- 2. ✍️ **RePermit** (`src/RePermit.sol`): Permit2-style EIP-712 signatures with witness data that bind allowances to exact order hashes, preventing signature reuse.
159
- 3. 🧾 **Cosigner** (`src/ops/Cosigner.sol`): Attests to trigger-time and current market prices with token validation.
160
- 4. 🛠️ **Executor** (`src/Executor.sol`): Whitelisted fillers that execute eligible orders, enforce minimum output, and distribute surplus.
161
- 5. 🔐 **WM** (`src/ops/WM.sol`): Two-step ownership allowlist manager for executors and admin functions with event emission.
162
- 6. 🏭 **Refinery** (`src/ops/Refinery.sol`): Operations utility for batching multicalls and sweeping token balances by basis points.
163
-
164
- ### Order Structure
165
-
166
- Based on `src/Structs.sol`, each order contains:
167
-
168
- ```solidity
169
- struct Order {
170
- address reactor; // OrderReactor contract address
171
- address executor; // Authorized executor for this order
172
- Exchange exchange; // Exchange parameters, referrer, and data
173
- address swapper; // Order creator/signer
174
- uint256 nonce; // Unique identifier
175
- uint256 start; // Earliest execution timestamp
176
- uint256 deadline; // Expiration timestamp
177
- uint256 chainid; // Chain ID for cross-chain validation
178
- uint32 exclusivity; // BPS-bounded exclusive execution
179
- uint32 epoch; // Seconds between fills (0 = single-use)
180
- uint32 slippage; // BPS applied to cosigned price
181
- uint32 freshness; // Cosignature validity window in seconds
182
- Input input; // Token to spend
183
- Output output; // Token to receive
184
- }
185
-
186
- struct Input {
187
- address token; // Input token address
188
- uint256 amount; // Per-fill chunk amount
189
- uint256 maxAmount; // Total amount across all fills
190
- }
191
-
192
- struct Output {
193
- address token; // Output token address
194
- uint256 limit; // Minimum acceptable output, in output-token decimals, per chunk
195
- uint256 triggerLower; // Lower trigger boundary, in output-token decimals, per chunk
196
- uint256 triggerUpper; // Upper trigger boundary, in output-token decimals, per chunk
197
- address recipient; // Where to send output tokens
198
- }
199
- ```
200
-
201
- ### Limits & Constants
202
-
203
- 1. **Maximum Slippage**: Up to 5,000 BPS, or 50%, inclusive, defined in `src/Constants.sol`.
204
- 2. **Basis Points**: 10,000 BPS equals 100%.
205
- 3. **Freshness Requirements**: Must be greater than 0 seconds and less than epoch duration when `epoch != 0`.
206
- 4. **Epoch Behavior**: `0` means single execution; values above `0` mean recurring execution with that interval.
207
- 5. **Gas Optimization**: Foundry optimizer runs are set to `1,000,000`.
208
-
209
- ### Multi-Chain Deployment
210
-
211
- The protocol is designed for deployment across EVM-compatible chains with deterministic addresses via CREATE2. Configuration is managed through [`config.json`](./config.json).
212
-
213
- ## For Integrators
214
-
215
- This repository ships these integration surfaces:
216
-
217
- 1. Root package `@orbs-network/spot` for config, build orchestration, contracts, and published metadata inputs.
218
- 2. Self-contained skill package [`skill/`](./skill/) published as `@orbs-network/spot-skill`.
219
- 3. Skills-only OpenAI plugin artifact generated with `npm run plugin:build` for marketplace testing and submission.
220
- 4. Hosted MCP endpoint at [`https://agents-sink.orbs.network/mcp`](https://agents-sink.orbs.network/mcp).
221
- 5. Hosted raw files at [`https://orbs-network.github.io/spot/`](https://orbs-network.github.io/spot/) for direct bundle consumption.
222
- 6. Hosted skill distribution on [Clawhub](https://clawhub.ai/eranp-orbs/spot-advanced-swap-orders) for direct skill discovery.
223
-
224
- ## Development
225
-
226
- ```bash
227
- npm install
228
- npm run build
229
- npm test
230
- npm run fmt
231
- ```
232
-
233
- Notes:
234
-
235
- 1. `npm run build` runs `npm run sync` and then `forge build --extra-output-files abi`.
236
- 2. `npm run plugin:build` generates the untracked plugin bundle at `dist/spot/`.
237
- 3. Use `forge test` for the Foundry suite.
238
-
239
- ## Contributing
240
-
241
- 1. Make the smallest coherent change.
242
- 2. Keep `skill/`, hosted MCP references, and any affected published surfaces in sync.
243
- 3. Run `npm run build` after changes.
244
- 4. Run tests when behavior changes or when explicitly requested.
245
-
246
- ## Operational Notes
247
-
248
- 1. **Executor ETH Refunds**: Order execution returns the reactor's ETH balance to the filler. Keep executors funded, and treat unexpected reactor ETH as recoverable by WM-allowed addresses.
249
- 2. **Input Tokens**: Orders spend ERC-20 tokens; wrap native ETH before creating orders.
250
-
251
- ## Support
252
-
253
- 1. **Issues**: Use GitHub Issues for bug reports and feature requests.
254
- 2. **Documentation**: The repo includes inline code documentation and the canonical skill references.
255
-
256
- ## License
257
-
258
- MIT. See [`LICENSE`](./LICENSE).
36
+ [MIT](./LICENSE).
package/config.json CHANGED
@@ -504,9 +504,10 @@
504
504
  "4663": {
505
505
  "adapter": {
506
506
  "Kyber": "0x6bbE14b2205a87FA0EAdE5f0795C7bb16B5347EA",
507
- "Magpie": "0xe757b37EDbE768f487a8Fc66BB48bbdb85412570",
508
507
  "OpenOcean": "0xF4087df1F43De3B8e84171c1434da5aE0355796C",
509
- "LiFi": "0xA75eA4C3570Ec0ebCbe79176B8D6E06839C36c84"
508
+ "LiFi": "0xA75eA4C3570Ec0ebCbe79176B8D6E06839C36c84",
509
+ "ZeroX": "0x196F49fafBC3A5B6BB3661660892978Ca3679927",
510
+ "OKX": "0x98Ccd2a85bdA82b628d4E043faA44C10ffa3de04"
510
511
  },
511
512
  "dex": {
512
513
  "orvex": {
@@ -535,5 +536,41 @@
535
536
  "fee": "0x28F6C9dBE21fFc146Af8d5D15c49Cf48F61140Dc"
536
537
  }
537
538
  }
539
+ },
540
+ "9745": {
541
+ "adapter": {
542
+ "Sushi": "0xA985f801ea74321AdcC9Ef88B394858CbA3F71ba",
543
+ "LiFi": "0xB75B57A3e99ADb78A3Be05ba235146F6bea6EA75",
544
+ "Kyber": "0x6bbE14b2205a87FA0EAdE5f0795C7bb16B5347EA",
545
+ "ZeroX": "0x196F49fafBC3A5B6BB3661660892978Ca3679927",
546
+ "OpenOcean": "0x2Be5260d030ff9A6040bA4292326B796ff1a055d",
547
+ "OKX": "0x31461FaE1a11723b1176Adb03A2e74477Df58785"
548
+ },
549
+ "dex": {}
550
+ },
551
+ "5000": {
552
+ "adapter": {
553
+ "Sushi": "0xA985f801ea74321AdcC9Ef88B394858CbA3F71ba",
554
+ "LiFi": "0xe8CD820d5bb34141C4bfd92544Ba9246fc6e8380",
555
+ "ZeroX": "0x9DB46f6359e06b2cBfeFEA61C9171221025f827e",
556
+ "OKX": "0xDD535A91c8166159FA08C4fcd5959c623A472B71"
557
+ },
558
+ "dex": {}
559
+ },
560
+ "57073": {
561
+ "adapter": {
562
+ "LiFi": "0xb9E1a6265dF9a860690A74C1482537061b1E3e28",
563
+ "ZeroX": "0x196F49fafBC3A5B6BB3661660892978Ca3679927",
564
+ "OKX": "0xCdb7F258DE544c4E2a40ed0092A5188B06f09318"
565
+ },
566
+ "dex": {}
567
+ },
568
+ "30": {
569
+ "adapter": {
570
+ "Sushi": "0xA985f801ea74321AdcC9Ef88B394858CbA3F71ba",
571
+ "LiFi": "0xe8CD820d5bb34141C4bfd92544Ba9246fc6e8380",
572
+ "OpenOcean": "0x2Be5260d030ff9A6040bA4292326B796ff1a055d"
573
+ },
574
+ "dex": {}
538
575
  }
539
576
  }
@@ -0,0 +1,28 @@
1
+ [
2
+ {
3
+ "type": "function",
4
+ "name": "IS_SCRIPT",
5
+ "inputs": [],
6
+ "outputs": [
7
+ {
8
+ "name": "",
9
+ "type": "bool",
10
+ "internalType": "bool"
11
+ }
12
+ ],
13
+ "stateMutability": "view"
14
+ },
15
+ {
16
+ "type": "function",
17
+ "name": "run",
18
+ "inputs": [],
19
+ "outputs": [
20
+ {
21
+ "name": "adapter",
22
+ "type": "address",
23
+ "internalType": "address"
24
+ }
25
+ ],
26
+ "stateMutability": "nonpayable"
27
+ }
28
+ ]