You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Train Protocol enables permissionless cross-chain token swaps without trusted intermediaries. Users lock funds on the source chain, solvers fulfill the swap on the destination chain, and atomic reveals ensure either both sides complete or both refund.
8
8
9
-
10
9
## Contract Architecture
11
10
12
11
### Single Unified Contract
@@ -61,6 +60,7 @@ struct UserLockParams {
61
60
```
62
61
63
62
**Requirements:**
63
+
64
64
-`amount > 0`
65
65
-`timelockDelta > 0`
66
66
-`block.timestamp < quoteExpiry`
@@ -72,6 +72,7 @@ struct UserLockParams {
72
72
Redeems a user lock with the secret preimage. Anyone can call this.
73
73
74
74
**Requirements:**
75
+
75
76
- Lock must exist and be pending
76
77
-`sha256(secret) == hashlock`
77
78
@@ -80,6 +81,7 @@ Redeems a user lock with the secret preimage. Anyone can call this.
80
81
Refunds a user lock back to the sender.
81
82
82
83
**Access Control:**
84
+
83
85
-`recipient` can refund **anytime**
84
86
- Anyone else can refund **after timelock expires**
85
87
@@ -166,6 +168,7 @@ All state-changing functions use OpenZeppelin's `ReentrancyGuard` with the `nonR
166
168
### ETH Transfer Gas Stipend
167
169
168
170
ETH transfers use a 10,000 gas stipend to prevent:
171
+
169
172
- Griefing attacks via gas-expensive `receive()` functions
170
173
- Reentrancy through ETH transfers
171
174
@@ -179,6 +182,7 @@ if (!success) revert TransferFailed();
179
182
### Safe Token Transfers
180
183
181
184
ERC20 transfers use OpenZeppelin's `SafeERC20` to handle:
185
+
182
186
- Tokens that don't return booleans (USDT)
183
187
- Tokens that revert on failure
184
188
- Tokens with non-standard implementations
@@ -213,20 +217,71 @@ Emitted when a lock is refunded.
213
217
214
218
## Error Codes
215
219
216
-
| Error | Description |
217
-
|-------|-------------|
218
-
|`ZeroAmount`| Lock amount is zero |
219
-
|`LockNotFound`| No lock exists for hashlock/index |
220
-
|`HashlockMismatch`| Provided secret doesn't hash to hashlock |
221
-
|`LockNotPending`| Lock already redeemed or refunded |
0 commit comments