|
| 1 | +--- |
| 2 | +name: review-exchange-bugs |
| 3 | +description: Reviews exchange plugins for common bugs and poor patterns. Use when reviewing any exchange plugin changes. |
| 4 | +--- |
| 5 | + |
| 6 | +Review the branch/pull request for common bugs and poor patterns specific to Edge exchange plugins. |
| 7 | + |
| 8 | +## Context Expected |
| 9 | + |
| 10 | +You will receive: |
| 11 | +- Repository name (edge-exchange-plugins) |
| 12 | +- Branch name |
| 13 | +- List of changed files to review |
| 14 | + |
| 15 | +## How to Review |
| 16 | + |
| 17 | +1. Read the changed plugin files provided in context |
| 18 | +2. Check for each bug pattern listed below |
| 19 | +3. Report findings with specific file:line references |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Separate Handlers for Different Asset Types |
| 24 | + |
| 25 | +When adding support for a new asset type (like Zcash), create a separate handler block rather than extending existing UTXO logic: |
| 26 | + |
| 27 | +```typescript |
| 28 | +// Incorrect - mixing ZEC with general UTXO handling |
| 29 | +} else { |
| 30 | + // UTXO block |
| 31 | + if (fromWallet.currencyInfo.pluginId === 'zcash') { |
| 32 | + // ZEC-specific code mixed in |
| 33 | + } |
| 34 | + // ... rest of UTXO handling |
| 35 | +} |
| 36 | + |
| 37 | +// Correct - separate block for ZEC |
| 38 | +} else if (fromWallet.currencyInfo.pluginId === 'zcash') { |
| 39 | + // ZEC-specific handling with all necessary checks |
| 40 | + if (thorAddress == null) throw new SwapCurrencyError(...) |
| 41 | + if (fromTokenId != null) throw new SwapCurrencyError(...) |
| 42 | + // ... ZEC-specific logic |
| 43 | +} else { |
| 44 | + // General UTXO handling |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +While Zcash is UTXO-based under the hood, Edge treats it differently. Keeping handlers separate makes code easier to maintain and reduces the chance of missing required checks. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Include All Validation Checks in New Handlers |
| 53 | + |
| 54 | +When creating a new asset handler by copying from an existing one, copy ALL validation checks: |
| 55 | + |
| 56 | +```typescript |
| 57 | +// UTXO block has token rejection check |
| 58 | +} else { |
| 59 | + if (fromTokenId != null) { |
| 60 | + throw new SwapCurrencyError(swapInfo, request) |
| 61 | + } |
| 62 | + // ... rest of UTXO logic |
| 63 | +} |
| 64 | + |
| 65 | +// New ZEC block - MUST include the same check |
| 66 | +} else if (fromWallet.currencyInfo.pluginId === 'zcash') { |
| 67 | + if (fromTokenId != null) { |
| 68 | + throw new SwapCurrencyError(swapInfo, request) // Don't forget this! |
| 69 | + } |
| 70 | + // ... ZEC logic |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +Missing validation checks can allow unsupported swap types to proceed. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Remove Invalid Destination When Adding Support |
| 79 | + |
| 80 | +If a previous commit blocked swaps to an asset, remove that block when adding destination support: |
| 81 | + |
| 82 | +```typescript |
| 83 | +// Previous state: ZEC swaps blocked |
| 84 | +INVALID_CURRENCY_CODES.to.zcash = ['ZEC'] |
| 85 | + |
| 86 | +// Adding ZEC receive support but forgetting to remove the block: |
| 87 | +// New ZEC receive handler (lines 388-392) NEVER RUNS because |
| 88 | +// checkInvalidCodes throws SwapCurrencyError first (lines 129-135) |
| 89 | + |
| 90 | +// Correct: Remove the invalid code entry when adding support |
| 91 | +// Delete: INVALID_CURRENCY_CODES.to.zcash = ['ZEC'] |
| 92 | +``` |
| 93 | + |
| 94 | +Always trace the swap flow to ensure new handlers are actually reachable. |
0 commit comments