feat: transfer TRUF in between network#158
Conversation
Time Submission Status
You can submit time with the command. Example: See available commands to help comply with our Guidelines. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a bridge token transfer feature: action-level amount validation and a new Action.transfer that calls ChangesBridge Token Transfer
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
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 unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
|
@holdex pr submit-time 4h |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/contracts-api/action.ts`:
- Around line 1159-1162: The current validation uses parseFloat on the amount
string (const numAmount = parseFloat(amount); ...), which can lose precision for
large wei values; replace this check with a string-based integer validation
(e.g., ensure amount matches /^[0-9]+$/ and is not "0") and remove parseFloat
usage, throwing the same Invalid amount error when the regex fails; apply the
identical change to the bridgeTokens validation block where parseFloat is used
so both places validate positive integer strings without converting to a float.
🪄 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: adf4d36d-bd86-40ed-9a08-913f9ffeee3f
📒 Files selected for processing (3)
docs/api-reference.mdsrc/client/client.tssrc/contracts-api/action.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/contracts-api/action.ts (2)
1152-1164: ⚡ Quick winValidate recipient address format before submitting transfer.
transferaccepts any recipient string, but docs require Ethereum address format. Fail fast in SDK to avoid avoidable chain call failures.Suggested fix
public async transfer( bridgeIdentifier: string, recipient: string, amount: string ): Promise<Types.GenericResponse<Types.TxReceipt>> { + // Fail fast on malformed destination address + new EthereumAddress(recipient); + if (!/^[0-9]+$/.test(amount) || amount === "0") { throw new Error(`Invalid amount: ${amount}. Amount must be greater than 0.`); }🤖 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/contracts-api/action.ts` around lines 1152 - 1164, The transfer method currently doesn't validate recipient format; add a pre-check inside transfer (before executeWithNamedParams) to ensure recipient is a valid Ethereum address (e.g. matches /^0x[a-fA-F0-9]{40}$/ or use an existing utility like ethers.utils.isAddress if available) and throw a clear Error such as `Invalid recipient address: ${recipient}` when it fails; keep the existing amount validation and then proceed to call transfer (`transfer` method) as before if the recipient is valid.
1112-1113: ⚡ Quick winExtract shared amount guard to avoid drift between transfer flows.
bridgeTokensandtransferduplicate the same validation block; centralizing it reduces divergence risk (especially for edge-case fixes).Suggested refactor
+ private validatePositiveWeiAmount(amount: string): void { + if (!/^[0-9]+$/.test(amount) || BigInt(amount) <= 0n) { + throw new Error(`Invalid amount: ${amount}. Amount must be greater than 0.`); + } + } public async bridgeTokens( @@ - if (!/^[0-9]+$/.test(amount) || amount === "0") { - throw new Error(`Invalid amount: ${amount}. Amount must be greater than 0.`); - } + this.validatePositiveWeiAmount(amount); @@ public async transfer( @@ - if (!/^[0-9]+$/.test(amount) || amount === "0") { - throw new Error(`Invalid amount: ${amount}. Amount must be greater than 0.`); - } + this.validatePositiveWeiAmount(amount);Also applies to: 1157-1159
🤖 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/contracts-api/action.ts` around lines 1112 - 1113, Extract the duplicated amount validation into a single helper (e.g., validateAmount or ensureAmountGreaterThanZero) and replace the inline checks in both bridgeTokens and transfer with a call to that helper; the helper should verify the string matches /^[0-9]+$/ and is not "0" and throw the same Error(`Invalid amount: ${amount}. Amount must be greater than 0.`) to preserve behavior. Update both call sites (the validation currently inside bridgeTokens and transfer) to use the new function and remove the duplicated regex/zero checks so future fixes only touch the shared helper.
🤖 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/contracts-api/action.ts`:
- Around line 1112-1113: The amount check currently allows zero-equivalent
strings like "00"; update the validation in both bridgeTokens and transfer to
ensure the numeric value is positive by combining the digits-only check with a
numeric BigInt comparison—i.e., replace the existing if that tests
/^[0-9]+$/.test(amount) || amount === "0" with a guard that ensures
/^[0-9]+$/.test(amount) && BigInt(amount) > 0, and throw the same error when
that condition fails.
---
Nitpick comments:
In `@src/contracts-api/action.ts`:
- Around line 1152-1164: The transfer method currently doesn't validate
recipient format; add a pre-check inside transfer (before
executeWithNamedParams) to ensure recipient is a valid Ethereum address (e.g.
matches /^0x[a-fA-F0-9]{40}$/ or use an existing utility like
ethers.utils.isAddress if available) and throw a clear Error such as `Invalid
recipient address: ${recipient}` when it fails; keep the existing amount
validation and then proceed to call transfer (`transfer` method) as before if
the recipient is valid.
- Around line 1112-1113: Extract the duplicated amount validation into a single
helper (e.g., validateAmount or ensureAmountGreaterThanZero) and replace the
inline checks in both bridgeTokens and transfer with a call to that helper; the
helper should verify the string matches /^[0-9]+$/ and is not "0" and throw the
same Error(`Invalid amount: ${amount}. Amount must be greater than 0.`) to
preserve behavior. Update both call sites (the validation currently inside
bridgeTokens and transfer) to use the new function and remove the duplicated
regex/zero checks so future fixes only touch the shared helper.
🪄 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: e65cce41-24fd-43a3-8bb5-2e8922ee8b27
📒 Files selected for processing (1)
src/contracts-api/action.ts
resolves: https://github.com/truflation/website/issues/3849
Summary by CodeRabbit
New Features
Changes