feat: pay to a crypto address using atomic swap#39
Conversation
📝 WalkthroughWalkthroughThis PR adds a complete Lightning-to-EVM atomic swap feature. It introduces the Lendaswap SDK dependency, implements a swap orchestration module with pair discovery and validation, registers a new ChangesLightning to EVM Swap Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/lendaswap/swap.ts (1)
154-154: 💤 Low valueConsider making the referral code configurable.
The referral code is hardcoded. If this code identifies the integration partner or revenue share, it might need to vary by deployment context (staging vs production, different integrators, etc.).
Consider allowing override via environment variable or configuration parameter.
♻️ Optional enhancement to support environment override
+const REFERRAL_CODE = process.env.LENDASWAP_REFERRAL_CODE || "lnds_2c07e38f10a28d47"; + async function createPaymentSwap(params: { pair: SupportedPair; amount: number; targetAddress: string; }): Promise<LightningToEvmSwapResponse> { const client = await getClient(); const targetAmount = toSmallestUnit(params.amount, params.pair.decimals); const targetAsset: Asset = { chain: params.pair.chain, tokenId: params.pair.tokenId, }; const result = await client.createSwap({ source: Asset.BTC_LIGHTNING, target: targetAsset, targetAmount, targetAddress: params.targetAddress, gasless: true, - referralCode: "lnds_2c07e38f10a28d47", + referralCode: REFERRAL_CODE, });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lendaswap/swap.ts` at line 154, The referralCode value is hardcoded in swap.ts (referralCode: "lnds_2c07e38f10a28d47"); make it configurable by reading a config or environment variable (e.g., process.env.LENDASWAP_REFERRAL_CODE) and falling back to the current default; update the code that constructs the payload/object containing referralCode (search for the referralCode symbol in swap.ts) to use the config/env value and add a brief comment and a unit/integration test or env-var mention in documentation to ensure deployments can override it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lendaswap/swap.ts`:
- Around line 131-133: The toSmallestUnit(amount: number, decimals: number)
function can overflow Number.MAX_SAFE_INTEGER when amount * 10**decimals is
large; update it to either use BigInt/BigNumber math or validate inputs and
reject amounts that would exceed safe integer range. Specifically, compute or
estimate the scaled value bounds (e.g., via Number.MAX_SAFE_INTEGER /
10**decimals) and throw a clear error from toSmallestUnit when amount is too
large or decimals too high, or change the implementation to return a
BigInt/string using BigInt( Math.round(...) ) or a BigNumber library so you
preserve precision for values like 1e12 with 6+ decimals.
- Around line 1-11: The package version for `@lendasat/lendaswap-sdk-pure`
referenced by the imports (Asset, Client, InMemorySwapStorage,
InMemoryWalletStorage, LightningToEvmSwapResponse, SwapStatus,
SwapStatusHandler, toChain, toChainName) appears unpublished; update the
dependency in package.json to a published tag (e.g., a confirmed published
version such as 0.2.24 or the latest published), run npm install to update
lockfile, then verify that all imported symbols (Client, Asset, toChain,
toChainName, InMemorySwapStorage, InMemoryWalletStorage, etc.) still exist in
that released version and adjust imports if names changed, and finally re-run
your advisory/CVE scan against the chosen exact version.
---
Nitpick comments:
In `@src/lendaswap/swap.ts`:
- Line 154: The referralCode value is hardcoded in swap.ts (referralCode:
"lnds_2c07e38f10a28d47"); make it configurable by reading a config or
environment variable (e.g., process.env.LENDASWAP_REFERRAL_CODE) and falling
back to the current default; update the code that constructs the payload/object
containing referralCode (search for the referralCode symbol in swap.ts) to use
the config/env value and add a brief comment and a unit/integration test or
env-var mention in documentation to ensure deployments can override it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2c9f6e10-43eb-4156-9427-4f085878e8fc
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (5)
package.jsonsrc/commands/pay-crypto.tssrc/index.tssrc/lendaswap/swap.tssrc/test/pay-crypto.test.ts
Closes #29
yarn dev pay-crypto 0xXXXXXXXXXXXXXXXXXXXX -a 2 --currency USDC --network arbitrum { "swap_id": "ddb301c6-df67-4dd3-91bb-5c08cd86062a", "status": "completed", "target": { "address": "0x78C01B70e43b7BD68c648cfa456D3c9Af99F67bC", "currency": "USDC", "network": "Arbitrum", "amount": 2 } }Summary by CodeRabbit
New Features
Tests