feat: join and fund an agent wallet in one call - #169
Conversation
Time Submission Status
Submit or update total time with: Add time on top of previous submission with: See available commands to help comply with our Guidelines. |
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a typed ChangesAtomic MAA join and funding
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Owner
participant MAAAction
participant Node
Owner->>MAAAction: joinAndFundAgentAddress
MAAAction->>Node: resolve rule
MAAAction->>Node: execute maa_join_and_fund
Node-->>MAAAction: return transaction hash
MAAAction-->>Owner: return derived address and tx hash
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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: 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/maaActions.ts`:
- Around line 149-150: The amount validation in maaActions.ts must require a
string, positive base-10 integer with at most 78 digits before any network call
or getRule operation; update the validation near the existing amount check
accordingly. In src/types/maa.ts lines 55-56, document the NUMERIC(78,0)
78-significant-digit maximum; in src/contracts-api/maaActions.test.ts lines
225-234, add pre-network rejection cases for a numeric amount and a 79-digit
string; and in examples/maa_lifecycle_example/README.md lines 48-57, state that
amount is a positive base-10 string fitting NUMERIC(78,0).
🪄 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: 7f5c948c-d974-4586-ad98-f67bcfbb922a
📒 Files selected for processing (5)
examples/maa_lifecycle_example/README.mdsrc/contracts-api/maaActions.test.tssrc/contracts-api/maaActions.tssrc/internal.tssrc/types/maa.ts
|
@holdex pr submit-time 5h |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@examples/maa_join_and_fund_example/.env.example`:
- Around line 28-30: Reorder the MAA_FEE_BPS and MAA_FUND_AMOUNT declarations in
the environment example so MAA_FEE_BPS appears before MAA_FUND_AMOUNT,
preserving both values and the existing comment.
In `@examples/maa_join_and_fund_example/package.json`:
- Around line 10-15: Update the `@trufnetwork/kwil-js` dependency in the example
package’s dependencies to match the root SDK version, changing the pinned
version from 0.9.12 to 0.9.14 while leaving the other dependencies unchanged.
🪄 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: a287c04c-2623-42cd-9d79-9b52db41827e
📒 Files selected for processing (8)
examples/maa_join_and_fund_example/.env.exampleexamples/maa_join_and_fund_example/README.mdexamples/maa_join_and_fund_example/main.tsexamples/maa_join_and_fund_example/package.jsonexamples/maa_lifecycle_example/README.mdsrc/contracts-api/maaActions.test.tssrc/contracts-api/maaActions.tssrc/types/maa.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/types/maa.ts
- src/contracts-api/maaActions.ts
- examples/maa_lifecycle_example/README.md
- src/contracts-api/maaActions.test.ts
| MAA_FUND_AMOUNT=10000000000000000000 | ||
| # Owner-withdraw commission paid to the agent, in basis points (250 = 2.5%). | ||
| MAA_FEE_BPS=250 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Reorder keys per dotenv-linter.
MAA_FEE_BPS should be declared before MAA_FUND_AMOUNT to satisfy the UnorderedKey check.
🔧 Proposed fix
-# Amount to fund the wallet with, in base units (a positive base-10 integer that fits
-# NUMERIC(78,0)). Default is 10 tokens. The owner must already hold at least this much.
-MAA_FUND_AMOUNT=10000000000000000000
# Owner-withdraw commission paid to the agent, in basis points (250 = 2.5%).
MAA_FEE_BPS=250
+# Amount to fund the wallet with, in base units (a positive base-10 integer that fits
+# NUMERIC(78,0)). Default is 10 tokens. The owner must already hold at least this much.
+MAA_FUND_AMOUNT=10000000000000000000📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| MAA_FUND_AMOUNT=10000000000000000000 | |
| # Owner-withdraw commission paid to the agent, in basis points (250 = 2.5%). | |
| MAA_FEE_BPS=250 | |
| # Owner-withdraw commission paid to the agent, in basis points (250 = 2.5%). | |
| MAA_FEE_BPS=250 | |
| # Amount to fund the wallet with, in base units (a positive base-10 integer that fits | |
| # NUMERIC(78,0)). Default is 10 tokens. The owner must already hold at least this much. | |
| MAA_FUND_AMOUNT=10000000000000000000 |
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 30-30: [UnorderedKey] The MAA_FEE_BPS key should go before the MAA_FUND_AMOUNT key
(UnorderedKey)
🤖 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 `@examples/maa_join_and_fund_example/.env.example` around lines 28 - 30,
Reorder the MAA_FEE_BPS and MAA_FUND_AMOUNT declarations in the environment
example so MAA_FEE_BPS appears before MAA_FUND_AMOUNT, preserving both values
and the existing comment.
Source: Linters/SAST tools
Adds
joinAndFundAgentAddress, so someone who already holds TRUF or USDC on TN can join a rule and fund the derived agent wallet in one signed transaction, instead of a join followed by a separate transfer. Either both legs commit or neither does, so activation can no longer strand a joined-but-unfunded wallet.resolves: trufnetwork/truf-network#1399
A kwil transaction runs exactly one action, so join + transfer can only be atomic inside a single on-chain action. That action shipped in the node (
maa_join_and_fund, merged in trufnetwork/node#1409); this exposes it as one SDK call.What is here
src/contracts-api/maaActions.ts—joinAndFundAgentAddress({ ruleId, bridge, amount }). MirrorsjoinAgentAddress: it resolves the rule on-chain and derives the wallet locally, so the caller learns the address before broadcast, then submits oneexecute. The$amountis pinned toNumeric(78, 0)so a plain JS string reaches the node as NUMERIC, not TEXT (the same pincreateAgentRuleuses for$fee_flat). Returns the derived address and the submission tx hash.src/types/maa.ts—MAAJoinAndFundInput;src/internal.ts— export.examples/maa_lifecycle_example/README.md— a note on the atomic path next to the two-step flow.Notes for review
getRuleand before broadcast.maa_join_and_fundaction (node migration 054). It errors on a live call until that migration is deployed to the target network.Testing
npm run test:unitgreen (326 tests, 8 new): the NUMERIC pin, local address derivation, raw-bytes rule id, and every guard (bad rule length, empty bridge, non-positive or non-integer amount, unknown rule, missing tx hash). Typecheck and build clean. Live end-to-end verification follows once the node action is deployed to testnet.Summary by CodeRabbit
joinAndFundAgentAddressfor atomically joining and funding a Modular Agent Address in a single on-chain transaction.ruleId,bridge, and fundingamount, and returns the transaction hash plus the derived agent wallet address..env.example, and runnable script) demonstrating an atomic activation smoke test workflow.