-
Notifications
You must be signed in to change notification settings - Fork 43
Sam/docs #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samholmes
wants to merge
11
commits into
master
Choose a base branch
from
sam/docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,297
−11
Open
Sam/docs #400
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b271d89
docs: Add comprehensive documentation for developers and AI agents
samholmes 8cd9384
docs: Add debug server instructions for faster development
samholmes dbb6b8c
docs: Add comprehensive plugin expectations and requirements
samholmes 3c93bc1
fix: Correct chain ID access and Edge type usage in docs
samholmes 040b93b
fix: Make tokenId documentation chain-agnostic
samholmes 0272d62
docs: Enhance swap plugin architecture documentation
samholmes f7dc569
refactor: Replace currency code terminology with symbol mapping
samholmes 6e5b73f
docs: Document proper error throwing patterns with priority
samholmes 13b7d31
docs: Emphasize API-driven validation principle
samholmes b2bd543
refactor: Remove remaining currency code references
samholmes 9d78e15
fix(docs): replace hallucinated API response examples with real ones
samholmes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Agent Guidelines for edge-exchange-plugins | ||
|
|
||
| ## Build/Test/Lint Commands | ||
|
|
||
| - **Test**: `npm test` (single test: `npm test -- test/path/to/file.test.ts`) | ||
| - **Lint**: `npm run lint` (auto-fix: `npm run fix`) | ||
| - **Type check**: `npm run types` | ||
| - **Build**: `npm run prepare` (runs clean, compile, types, and webpack) | ||
| - **Verify all**: `npm run verify` (build + lint + types + test) | ||
|
|
||
| ## Code Style Guidelines | ||
|
|
||
| - **TypeScript**: Strict mode enabled, use type imports (`import type { ... }`) | ||
| - **Imports**: Sort with `simple-import-sort`, no default exports | ||
| - **Formatting**: 2-space indentation, semicolons required, trailing commas | ||
| - **Naming**: camelCase for variables/functions, PascalCase for types/interfaces | ||
| - **Files**: Use `.ts` extension, organize by feature in `src/swap/` | ||
| - **Async**: Always use async/await over promises, handle errors with try/catch | ||
| - **Exports**: Named exports only, group related functionality | ||
| - **Dependencies**: Use `cleaners` for runtime validation, `biggystring` for numbers | ||
| - **Constants**: UPPER_SNAKE_CASE for true constants, extract magic numbers | ||
| - **Error handling**: Throw specific Edge error types (e.g., SwapCurrencyError) | ||
|
|
||
| ## Documentation Index | ||
|
|
||
| ### Setup & Configuration | ||
|
|
||
| - `README.md` - **When to read**: Initial setup, installation, adding exchanges | ||
| - **Summary**: Setup instructions, development guide, PR requirements | ||
|
|
||
| ### Detailed Documentation | ||
|
|
||
| - `docs/conventions/edge-company-conventions.md` - **When to read**: Starting development | ||
| - **Summary**: Company-wide Edge conventions, git workflow, PR rules | ||
| - `docs/conventions/typescript-style-guide.md` - **When to read**: Writing new code | ||
| - **Summary**: Import rules, type safety, error handling, naming conventions | ||
| - `docs/patterns/swap-plugin-architecture.md` - **When to read**: Creating new plugins | ||
| - **Summary**: Plugin structure, categories, common patterns, best practices | ||
| - `docs/business-rules/wallet-validation-rules.md` - **When to read**: Implementing DEX plugins | ||
| - **Summary**: Critical wallet requirements for DEX/DeFi integrations | ||
| - `docs/guides/adding-new-exchange.md` - **When to read**: Adding exchange support | ||
| - **Summary**: Step-by-step guide for new exchange integration | ||
| - `docs/references/api-deprecations.md` - **When to read**: Seeing deprecation warnings | ||
| - **Summary**: Deprecated APIs, migration paths, impact assessment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Wallet Validation Rules | ||
|
|
||
| **Date**: 2025-08-20 | ||
|
|
||
| ## Critical Business Rules | ||
|
|
||
| ### Same Wallet Requirements | ||
|
|
||
| Several DEX plugins **must** use the same wallet for source and destination: | ||
|
|
||
| 1. **XRP DEX** (`src/swap/defi/xrpDex.ts`) | ||
|
|
||
| ```typescript | ||
| // Source and dest wallet must be the same | ||
| if (request.fromWallet !== request.toWallet) { | ||
| throw new Error("XRP DEX must use same wallet for source and destination"); | ||
| } | ||
| ``` | ||
|
|
||
| 2. **0x Gasless** (`src/swap/defi/0x/0xGasless.ts`) | ||
|
|
||
| ```typescript | ||
| // The fromWallet and toWallet must be of the same because the swap | ||
| ``` | ||
|
|
||
| 3. **Fantom Sonic Upgrade** (`src/swap/defi/fantomSonicUpgrade.ts`) | ||
| ```typescript | ||
| if (fromAddress !== toAddress) { | ||
| throw new Error("From and to addresses must be the same"); | ||
| } | ||
| ``` | ||
|
|
||
| ### Chain Validation | ||
|
|
||
| Uniswap V2-based plugins validate that both wallets are on the same chain: | ||
|
|
||
| 1. **TombSwap** (`src/swap/defi/uni-v2-based/plugins/tombSwap.ts`) | ||
| 2. **SpookySwap** (`src/swap/defi/uni-v2-based/plugins/spookySwap.ts`) | ||
| ```typescript | ||
| // Sanity check: Both wallets should be of the same chain. | ||
| ``` | ||
|
|
||
| ## Rationale | ||
|
|
||
| ### DEX Same-Wallet Requirement | ||
|
|
||
| - DEX swaps happen in a single transaction on-chain | ||
| - The wallet executing the swap receives the output tokens | ||
| - Cross-wallet swaps would require additional transfer transactions | ||
|
|
||
| ### Chain Validation | ||
|
|
||
| - Prevents accidental cross-chain swap attempts | ||
| - Ensures contract addresses are valid for the target chain | ||
| - Protects users from losing funds due to chain mismatches | ||
|
|
||
| ## Implementation Guidelines | ||
|
|
||
| When implementing a new DEX plugin: | ||
|
|
||
| 1. **Always validate wallet compatibility** early in `fetchSwapQuote` | ||
| 2. **Throw descriptive errors** that explain the limitation | ||
| 3. **Document the requirement** in the plugin's swapInfo | ||
|
|
||
| Example validation: | ||
|
|
||
| ```typescript | ||
| async fetchSwapQuote(request: EdgeSwapRequest): Promise<EdgeSwapQuote> { | ||
| // Validate same wallet requirement for DEX | ||
| if (request.fromWallet !== request.toWallet) { | ||
| throw new Error(`${swapInfo.displayName} requires same wallet for swap`) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a new swap error specifically for this. See SwapAddressError in fantomSonicUpgrade.ts |
||
| } | ||
|
|
||
| // Continue with quote logic... | ||
| } | ||
| ``` | ||
|
|
||
| ## Exceptions | ||
|
|
||
| Centralized exchange plugins (`/central/`) typically support cross-wallet swaps because: | ||
|
|
||
| - They use deposit addresses | ||
| - The exchange handles the actual swap | ||
| - Funds can be sent to any destination address | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Edge Company Conventions | ||
|
|
||
| **Date**: 2025-08-20 | ||
|
|
||
| ## Overview | ||
|
|
||
| This document references the company-wide Edge development conventions that apply to all Edge projects, including edge-exchange-plugins. | ||
|
|
||
| ## Edge Conventions Repository | ||
|
|
||
| The official Edge conventions are maintained at: https://github.com/EdgeApp/edge-conventions | ||
|
|
||
| ### Key Convention Categories | ||
|
|
||
| 1. **Code Conventions** | ||
|
|
||
| - [JavaScript Code Conventions](https://github.com/EdgeApp/edge-conventions/blob/master/code/javascriptCode.md) | ||
| - [JavaScript Project Setup](https://github.com/EdgeApp/edge-conventions/blob/master/code/javascriptSetup.md) | ||
| - [React Conventions](https://github.com/EdgeApp/edge-conventions/blob/master/code/react.md) | ||
| - [Redux Conventions](https://github.com/EdgeApp/edge-conventions/blob/master/code/redux.md) | ||
|
|
||
| 2. **Git Conventions** | ||
|
|
||
| - [Commit Rules](https://github.com/EdgeApp/edge-conventions/blob/master/git/commit.md) | ||
| - [Pull Request Rules](https://github.com/EdgeApp/edge-conventions/blob/master/git/pr.md) | ||
| - [Git "Future Commit" Workflow](https://github.com/EdgeApp/edge-conventions/blob/master/git/future-commit.md) | ||
|
|
||
| 3. **Documentation Standards** | ||
| - [Documentation Conventions](https://github.com/EdgeApp/edge-conventions/blob/master/docs.md) | ||
|
|
||
| ## How These Apply to edge-exchange-plugins | ||
|
|
||
| ### Code Standards | ||
|
|
||
| While edge-exchange-plugins uses TypeScript (not plain JavaScript), many principles from the JavaScript conventions still apply: | ||
|
|
||
| - Consistent formatting and style | ||
| - Clear naming conventions | ||
| - Proper error handling patterns | ||
|
|
||
| ### Git Workflow | ||
|
|
||
| All Edge projects follow the same git conventions: | ||
|
|
||
| - **Commit messages** should follow the Edge commit rules | ||
| - **Pull requests** must meet the PR requirements | ||
| - **Branching** follows the documented patterns | ||
|
|
||
| ### Additional Project-Specific Conventions | ||
|
|
||
| This project extends the Edge conventions with TypeScript-specific rules documented in: | ||
|
|
||
| - [TypeScript Style Guide](./typescript-style-guide.md) - Project-specific TypeScript conventions | ||
|
|
||
| ## Important Notes | ||
|
|
||
| 1. **Company conventions take precedence** - When in doubt, follow the Edge conventions | ||
| 2. **TypeScript additions** - This project adds TypeScript-specific rules on top of the base conventions | ||
| 3. **PR requirements** - All PRs must follow both Edge conventions and project-specific requirements | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| For edge-exchange-plugins developers: | ||
|
|
||
| 1. Read the [Edge conventions](https://github.com/EdgeApp/edge-conventions) first | ||
| 2. Then read our [TypeScript Style Guide](./typescript-style-guide.md) for project-specific rules | ||
| 3. Follow the [PR rules](https://github.com/EdgeApp/edge-conventions/blob/master/git/pr.md) when submitting changes |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. Most DEXs can have different source and dest addresses. Only the XRP DEX and the Fantom/Sonic bridge require this